Android的布局为多个屏幕大小多个、布局、屏幕、大小

由网友(余生安好)分享简介:我的工作,我们正在针对所有的屏幕尺寸Android应用程序?我如何去让我的布局?我应该做出不同的layout.xml为每种类型的屏幕还是有做事情的任何其他有效的方式?I'm working on an android app that we're targeting for all screen sizes? How...

我的工作,我们正在针对所有的屏幕尺寸Android应用程序?我如何去让我的布局?我应该做出不同的layout.xml为每种类型的屏幕还是有做事情的任何其他有效的方式?

I'm working on an android app that we're targeting for all screen sizes? How do i go about making my layouts? Shall i make a different layout.xml for each type of screen or is there any other "efficient" way of doing things?

推荐答案

阅读支持多个屏幕的,特别是部分的最佳实践屏独立的。

Read Supporting Multiple Screens, specially the section "Best practices for Screen Independence".

基本规则:

使用WRAP_CONTENT,FILL_PARENT,或DP单元(而不是像素),在XML布局文件中指定的尺寸时 请不要使用AbsoluteLayout 请不要在您的code使用硬codeD像素值 使用密度和/或分辨率的特定资源 在实践中,即使您的布局将工作在平板电脑上,你也将需要提供不同的布局对于那些超大型设备,以提高用户体验。

编辑关于你的截图。

<ImageButton
        android:id="@+id/btnSubmit"
        android:src="@drawable/submit"
        android:layout_height="22dp"
        android:layout_width="85dp"
        android:layout_marginTop="15dp"
        android:layout_below="@+id/confirmpassword"
        android:layout_centerInParent="true" />

您指定这里有两个可能不玩好起来的垂直约束。相反layout_centerInParent,尽量layout_centerHorizo​​ntal。

You specify here two vertical constraints that might not play well together. Instead of layout_centerInParent, try layout_centerHorizontal.

您也可以给一个重力=。所以默认元素得到居中在水平方向的视图和获得粘到顶部。

You could also give a gravity="top|center_horizontal" to your RelativeLayout. So by default the elements get centered in the view horizontally and get sticked to the top.

也尝试调整姓名下面 btnSignin ,而不是用户名。你可能是幸运的。

Also try to align firstname below btnSignin instead of username. You might be lucky.

RelativeLayout的是最复杂的布局时使用。如果你不能一段时间之后得到它,你可以简单地决定依傍使用嵌套的LinearLayout的组合

RelativeLayout is the most complicated layout to use. If you can't get it right after some time, you could simply decide to fall back on using combinations of nested LinearLayout