您的位置:首页 > 移动开发 > Android开发

android 初学之XML小技巧小结---自适应各种分辨率屏幕

2012-04-23 12:54 323 查看
迫于实习公司强压,学习了android的xml界面设计。虽然有人力图说用activity就可以解决切,干嘛还死心专研XML?笔者给出自己的答案,无论任何应用开发,离不开,

行为层

结构层

表示层

拿html来说,JS是行为层,CSS是结构层,html就是表示层。3层分离各不干绕才完成了所谓模块化开发。

闲言少续

小技巧之一:如何让xml适应各种分辨率屏幕?

笔者初期研究:dp,sp,xp看的混天黑地,以为拿到dp就可以无敌,当然仅限于4in下屏幕,7in就走样了。正确做法是,width 和height 都用“fill_parent”表示占满整个父布局,或者“wrap_content”表示完整填充子布局的内容.那该问了,坐标呢?

layout_weight 权重划分。

举个例子

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1">
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1">
</FrameLayout>
<TextView
style="@style/textIni"
android:id="@+id/textId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textId"
android:layout_weight="1"	/>
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1">
</FrameLayout>
<EditText
android:id="@+id/editId"
style="@style/editId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5.52"
android:hint="@string/editId"
/>
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
效果如下,账户那一栏就是如上布局的结果,



好了,利用layout_weight,所有屏幕都会按比例显示控件,轻松多了吧?

————————————————————————————————————————————————————————————————

先写到这里,下次继续

先写这咯
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐