如你所知,Android今天有许多版本,许多构造函数,许多屏幕尺寸,......
今天的开发人员很难编写针对大部分设备的程序.
什么是开发人员必须知道的做法?
还有其他想法吗?
首先,您应该首先阅读官方的支持多屏幕最佳实践.有很多很好的提示出现,以及你需要在兼容性方面要寻找什么总体思路.
我发现有一件事非常有用,这似乎很明显,实际上是在各种大小的模拟器中测试你的布局.扩展到1024x768时,您的布局如何显示(即使没有设备会有这样的res)?当它超级小而方正的时候怎么样?了解您的布局如何延伸/收缩将帮助您调整它以更好地适应所有屏幕.
layout_weight在布局中,android:layout_weight是一个功能强大但未记录的属性.使用它,您可以创建布局,其中组件的大小按百分比相互组合.
例如:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_weight="80"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:layout_weight="20"
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在此布局中,<EditText/>将占用可用宽度的80%,而<Button/>将占用可用宽度的20%.显然,应谨慎使用,以便所有物品即使很小也可以使用.
<include />另一个有用的布局实践是将布局的常用位捆绑到单独的文件中并使用它们包含它们<include layout="@layout/smaller_section" />.这样,你可以洗牌周围的布局(比如,景观)的其他部分,而不必保留布局的整个并行版本.
| 归档时间: |
|
| 查看次数: |
569 次 |
| 最近记录: |