我觉得我是唯一一个迷失在这里的人。每个人似乎都很喜欢使用DP来使应用程序跨越多种屏幕尺寸。对我来说,每当我加载另一个屏幕时,对齐将永远不会正确地缩放。但是,如果我使用android:weight,所有设备上的所有东西都可以很好地缩放。我对于所有的东西都使用android权重的问题是,它并不总是想将图像调整到布局中,更不用说使用嵌套权重的警告了。Android支持所有屏幕尺寸
我看到的一个解决方案是为每个可能的屏幕尺寸创建一个新的屏幕尺寸。这是其他人做的吗?起初,我认为我们只需要创建x大,小等布局,但发现即使这些布局不适合各种屏幕尺寸(即使nexus 7也不适合这些类别) 。
示例代码
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:background="@drawable/layout_border"
android:padding="10dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:contentDescription="@string/app_name"
android:src="@drawable/yg" />
<ProgressBar
android:id="@+id/progressBar2"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/imageView1"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:progress="50" />
<TextView
android:id="@+id/textView1"
style="@style/NormalFont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/progressBar2"
android:layout_alignLeft="@+id/progressBar2"
android:layout_marginLeft="36dp"
android:text="@string/exercise_percent" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_above="@+id/textView1"
android:layout_toRightOf="@+id/imageView1"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
android:background="@drawable/start"
android:onClick="meditateTask" />
</RelativeLayout>
例如,这里的ImageButton我会出发生在每一个新的屏幕尺寸。
你能提供一个或多个布局示例并描述你每个人遇到的问题吗? –
添加了一个似乎不想正确对齐的示例布局。 – user3171099
android:layout_weight用于按比例**按比例缩放一个维度(例如,在%中,以esemplificate)。嵌套的重量**对性能**不利。除此之外,您可以使用** 9 Patches **,** dp **(与设备无关的像素),以及带有特设图形和尺寸的良好的旧**可绘制和值**文件夹。 ** TABLETS **属于另一类drawables/values文件夹。 –