安卓同屏分辨率 [英] Android same screen resolution

查看:86
本文介绍了安卓同屏分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Android, I need same resolution for Default(WVGA800) HVGA QVGA and all emulator that mean emulator's size should not matter right now I've this xml file and I'll need fix size for the bottom tab bar for that also what should I do? right now I am facing problem is.. I've to put space for tabbar at the bottom. so, when I'am run this same application in the Default(WVGA800) HVGA or QVGA it overlaps the webview on the tab bar so, it looks bad what should I do? I am using 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);
    }

我该怎么做,上面的问题就解决了?

what should I do so, above problem will be solve?

推荐答案

这里有几个问题:

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

  • You can't get the same layout to work in all the different screens. This has been repeated over and over here, and in the android dev guide. As explained in that link, you'll have to set up layout folders for each screen resolution group and create layouts for each one of them with the required sizes (at least res/layout-small, res/layout-normal and res/layout-large). Also, you will probably need to create a set of bitmaps (if you have any) for each screen density (res/drawable-hdpi, res/drawable-mdpi and res/drawable-ldpi at least).

如果您想修复底部的选项卡,请按照此问题的答案进行操作:如何降低标签栏高度并在底部显示.

If you want to fix the tab at the bottom, follow the answers to this question: How to reduce the tab bar height and display in bottom.

如果您使用 RelativeLayout 而不是 LinearLayout,然后你可以使用 android:layout_above="@id/tabs" 来强制 android 渲染所有 above> 标签并且不要重叠.

If you use a RelativeLayout instead of a LinearLayout, then you can use android:layout_above="@id/tabs" to force android to render everything above the tabs and not overlapping them.

如果内容大于屏幕,则考虑将您的布局包含在 ScrollView.

If the content is bigger than the screen, then consider including your layout inside a ScrollView.

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

Not relevant to this question, but very relevant for future questions in SO: please, try to avoid posting irrelevant code. The Java part has no interest in your question.

这篇关于安卓同屏分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆