gpt4 book ai didi

android - 相同的布局在 Samsung Galaxy Tab 上看起来不同

转载 作者:行者123 更新时间:2023-11-29 14:40:25 25 4
gpt4 key购买 nike

我正在开发一个 Android 2.2.2 应用程序,它将支持多种屏幕尺寸并且所有屏幕都是纵向的。我不会支持横向。

我已经在 HTC Desire 和三星 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、hdpi 和 x-hdpi 的图像。

背景图片看起来不错,但是所有小部件(TextViewProgressBarImageButton 等)都没有在正确的位置,当我在 Samsung Galaxy Tab 上进行测试。

我使用“Nexus One”作为模型在 Eclipse 上设计了这个布局。

Here人们建议我对每个屏幕尺寸和密度只使用一种布局,但它不起作用。我使用的是 dp 单位和 fill_parent 等,但它在 Galaxy Tab 上有所不同。

我是否需要针对 x-large 屏幕尺寸的布局?

最佳答案

确实,您收到的建议很好:可能只有一个布局文件,但正如评论中已经建议的那样,硬编码尺寸并不好 , 即使你使用 dpdip ,特别是当您针对所有可用的屏幕尺寸和密度时。

相反,您应该将这些值替换为维度值的链接

例如,而不是 android:layout_marginLeft="10dp" , 你会有类似的东西

android:layout_marginLeft="@dimen/textview_margin_left"

其中textview_margin_left定义在dimens.xml中,在不同的文件夹中有不同的值;
可能在文件夹 values 中:<dimen name="textview_margin_left">10dp</dimen> ,
在文件夹 values-large 中:<dimen name="textview_margin_left">20dp</dimen> ,
而在 values-xlarge 中:<dimen name="textview_margin_left">30dp</dimen>

但这只是一个示例,您必须在所有尺寸和分辨率上进行测试,并为您的布局找到最佳值。在 Eclipse 中,在 Graphical Layout 中模式下,您可以轻松了解您的布局在各种设备上的外观,只需单击 Nexus One,然后从列表中选择另一个型号,布局就会自动更新。

此外,您可以入住dimens.xml所有文本大小,这对于超大型设备非常有用。

仅使用一个 RelativeLayout取而代之的是许多叠瓦状的 LinearLayouts也可能是一个好主意,并为您的对象使用相对定位,而不是一些硬编码值。

关于android - 相同的布局在 Samsung Galaxy Tab 上看起来不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11626248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com