本文介绍了相同的布局看起来对三星Galaxy Tab不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android 2.2.2应用程序,它支持多个屏幕大小和所有的屏幕都画像。我不会支持的风景线。

I'm developing an Android 2.2.2 application which will support multiple screens sizes and all screens will be portrait. I won't support landscape.

我有测试以下布局上的HTC Desire和三星的Galaxy Tab 7.7。

I have test the following layout on an HTC Desire and on a Samsung Galaxy Tab 7.7.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/no_conectado"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/labelSelGateName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginTop="80dp" />

    <TextView
        android:id="@+id/labelSelOpened"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <ProgressBar
        android:id="@+id/indicatorActivityView"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginTop="22dp"
        android:layout_gravity="center_horizontal" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="110dp"
        android:layout_marginTop="60dp"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btnMyGates"
            android:layout_width="50dp"
            android:layout_height="110dp"
            android:layout_marginLeft="20dp"
            android:layout_weight=".33"
            android:background="@null"
            android:contentDescription="@string/layout_empty"
            android:onClick="onGateClick" />

        <LinearLayout
            android:layout_width="90dp"
            android:layout_height="110dp"
            android:layout_weight=".33"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btnOpen"
                android:layout_width="90dp"
                android:layout_height="55dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@null"
                android:contentDescription="@string/layout_empty"
                android:onClick="onOpenDoorClick" />

            <ImageButton
                android:id="@+id/btnClose"
                android:layout_width="90dp"
                android:layout_height="50dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@null"
                android:contentDescription="@string/layout_empty"
                android:onClick="onCloseDoorClick" />

        </LinearLayout>

        <ImageButton
            android:id="@+id/btnOptions"
            android:layout_width="50dp"
            android:layout_height="110dp"
            android:layout_marginRight="20dp"
            android:layout_weight=".33"
            android:background="@null"
            android:contentDescription="@string/layout_empty"
            android:onClick="onOptionClick" />

    </LinearLayout>

    <ImageButton
        android:id="@+id/btnFaqs"
        android:layout_width="110dp"
        android:layout_height="60dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:background="@null"
        android:contentDescription="@string/layout_empty"
        android:onClick="onFAQClick" />

    <ImageButton
        android:id="@+id/btnInfo"
        android:layout_width="110dp"
        android:layout_height="60dp"
        android:layout_gravity="right"
        android:layout_marginTop="20dp"
        android:background="@null"
        android:contentDescription="@string/layout_empty"
        android:onClick="onInfoClick" />

</LinearLayout>

我有图像LDPI,MDPI,华电国际和X-华电国际

I have images for ldpi, mdpi, hdpi and x-hdpi.

背景图片看起来不错,但所有小(的TextView 进度的ImageButton ,等等)是不是在正确的位置,当我测试的三星Galaxy Tab。

Background image looks great, but all widgets (TextView, ProgressBar, ImageButton, etc) aren't in the right position when I test it on Samsung Galaxy Tab.

我设计了Eclipse的这种布局使用的Nexus One`的一种模式。

I have designed this layout on Eclipse using 'Nexus One` as a model.

Here人都建议我,只使用一个布局,每一个屏幕大小和densitiy,但它不工作。我使用 DP 单位和 FILL_PARENT 等,但它是Galaxy Tab的不同。

Here people are recommend me that use only one layout for every screen size and densitiy, but it doesn't work. I'm using dp units and fill_parent, etc. but it is different on Galaxy Tab.

我需要为布局 X-LARGE 的屏幕尺寸?

Do I need a layout for x-large screen sizes?

推荐答案

事实上,你收到的建议是很好的:它可能只有一个布局文件,但因为它在注释中已经提出, 这不是很好的硬code尺寸,即使你使用 DP ,特别是当你的目标所有的屏幕大小和可用密度。

Indeed, the advice you received was good: it's possible to have only one layout file, but as it was already suggested in comments, it's not good to hardcode dimensions, even if you use dp or dip, specially when you are targeting all the screen sizes and densities available.

相反,你应该的链接到尺寸值替换这些值

Instead, you should replace those values with links to dimensions values.

例如,而不是安卓layout_marginLeft =10dp,你必须像

For example, instead of android:layout_marginLeft="10dp", you'll have something like

android:layout_marginLeft="@dimen/textview_margin_left"

其中 textview_margin_left 在dimens.xml定义,具有不同的文件夹不同的值;
大概是在文件夹中的&LT;扪名=textview_margin_left&GT; 10dp&LT; /扪&GT;
在文件夹中的价值观大&LT;扪名=textview_margin_left&GT; 20dp&LT; /扪&GT;
而在价值观XLARGE &LT;扪名=textview_margin_left&GT; 30dp&LT; /扪&GT;

where textview_margin_left is defined in the dimens.xml, having different values in different folders;
probably in folder values: <dimen name="textview_margin_left">10dp</dimen>,
in folder values-large: <dimen name="textview_margin_left">20dp</dimen>,
while in values-xlarge: <dimen name="textview_margin_left">30dp</dimen>

但是,这只是一个例子,你必须测试所有尺寸和分辨率,并找到你的布局的最佳值。在的Eclipse 图形布局模式下,你可以很容易地了解自己的布局看起来在各种设备上的想法,只是通过点击的 Nexus One的的,并从列表中选择另一种模式,并且布局将自动更新。

But this is just an example, you have to test on all dimensions and resolutions and find the best values for your layout. In Eclipse, in Graphical Layout mode, you can easily get an idea about how your layout looks on various devices, just by clicking on Nexus One, and choosing another model from the list, and the layout will automatically update.

此外,您还可以在 dimens.xml 所有文字大小移动,这将是非常有用的X大的设备。

Also, you can move in dimens.xml all the text sizes, and that will be very useful for x-large devices.

仅使用一个 RelativeLayout的,而不是许多叠瓦状 LinearLayouts 也可能是一个不错的主意,并采用了相对定位的对象,而不是一些硬codeD值的。

Using only one RelativeLayout instead many imbricated LinearLayouts might also be a good idea, and using relative positioning for your objects, instead some of the hardcoded values.

这篇关于相同的布局看起来对三星Galaxy Tab不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:09