【问题标题】:Android same screen resolutionAndroid同屏分辨率
【发布时间】:2011-06-11 04:07:53
【问题描述】:

在 Android 中,Default(WVGA800) 需要相同的分辨率 HVGA QVGA 和所有意味着模拟器大小的模拟器现在应该无关紧要我有这个xml file,我需要固定底部标签栏的大小,我该怎么办?现在我面临的问题是..我必须在底部放置标签栏的空间。所以,当我在 Default(WVGA800) HVGA 或 QVGA 中运行相同的应用程序时,它会与选项卡栏上的 webview 重叠,所以看起来很糟糕,我该怎么办?我正在使用 Android 1.6

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"   android:id="@+id/rl"
        android:layout_height="371dip">
    <!--    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"-->
    <!--        android:layout_height="fill_parent" />-->
    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <Button android:id="@+id/My_btn"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:gravity="center" android:textSize="8px" android:text="Download this mp3 file"
    android:textColor="@color/white" 
            android:layout_width="fill_parent" android:layout_height="33dip"
            android:visibility="invisible" />
        <Button android:id="@+id/My_btn1"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:text="this is button !"
            android:layout_width="0dip" android:layout_height="0dip"
            android:visibility="invisible" />
    </RelativeLayout>

这是我的标签栏活动类

final TabHost tabHost = (TabHost) getTabHost();
        try {

            //GlobalVariable.Setdownload(0);
            tabHost.addTab(createTab(myclsname.class, "Welcome",
                    "Welcome", R.drawable.tab_icon_events));
            tabHost.addTab(createTab(anotheclsname.class, ".Mp3List", ".Mp3List",
                    R.drawable.tab_icon_pitchforkfm));
            tabHost.addTab(createTab(AboutUs.class, "AboutUs", "AboutUs",
                    R.drawable.tab_icon_home));
            tabHost.addTab(createTab(ExtraInfromation.class, "ExtraInformation", "ExtraInformation",
                    R.drawable.tab_icon_tv));

            tabHost.setCurrentTab(1);
        } catch (Exception e) {
            // TODO: handle exception
        }
        tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(0).getLayoutParams().height=57;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;
tabHost.setOnTabChangedListener(new OnTabChangeListener() {

    bla.. bla.. bla..

    private TabSpec createTab(final Class<?> intentClass, final String tag,
            final String title, final int drawable) 
    {
        final Intent intent = new Intent().setClass(this, intentClass);

        final View tab = LayoutInflater.from(getTabHost().getContext())
                .inflate(R.layout.tab, null);
        ((TextView) tab.findViewById(R.id.tab_text)).setText(title);
        ((ImageView) tab.findViewById(R.id.tab_icon))
                .setImageResource(drawable);

        return getTabHost().newTabSpec(tag).setIndicator(tab)
                .setContent(intent);
    }

我该怎么办,上面的问题会解决吗?

【问题讨论】:

  • 分辨率相同但分辨率不同的屏幕?如果可能的话,它看起来会很糟糕(就像在 ipad 上以 2 倍的速度运行 iphone 应用程序)。

标签: android screen-resolution


【解决方案1】:

这里有几个问题:

  • 您无法在所有不同的屏幕上使用相同的布局。这在此处和android dev guide 中反复重复。如该链接中所述,您必须为每个屏幕分辨率组设置布局文件夹,并为每个屏幕分辨率组创建所需大小的布局(至少res/layout-smallres/layout-normalres/layout-large)。此外,您可能需要为每个屏幕密度(至少res/drawable-hdpires/drawable-mdpires/drawable-ldpi)创建一组位图(如果有的话)。

  • 如果要修复底部的选项卡,请按照以下问题的答案进行操作:How to reduce the tab bar height and display in bottom

  • 1234563 /strong> 他们。
  • 如果内容大于屏幕,请考虑将您的布局包含在 ScrollView 中。

  • 与此问题无关,但与 SO 中的未来问题非常相关:请尽量避免发布不相关的代码。 Java 部分对您的问题不感兴趣。

【讨论】:

  • 好吧,你的意思是说我必须为每个分辨率创建 main.xml 文件?
  • 但是它怎么能提供setcontentview呢?我的意思是如何确定要加载哪个 main.xml 文件?
  • 运行时会根据设备的屏幕自动确定。请阅读我发布的链接。我会在这里重复一遍:developer.android.com/guide/practices/screens_support.html,以防你错过。
  • 嗨@Aleadam,如果Java部分与问题无关,我会邀请您从问题中编辑它。 (我不会自己做,因为我对 Android 了解不够)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多