android 初学之XML小技巧小结---自适应各种分辨率屏幕
2012-04-23 12:54
323 查看
迫于实习公司强压,学习了android的xml界面设计。虽然有人力图说用activity就可以解决切,干嘛还死心专研XML?笔者给出自己的答案,无论任何应用开发,离不开,
行为层
拿html来说,JS是行为层,CSS是结构层,html就是表示层。3层分离各不干绕才完成了所谓模块化开发。
闲言少续
layout_weight 权重划分。
举个例子
好了,利用layout_weight,所有屏幕都会按比例显示控件,轻松多了吧?
————————————————————————————————————————————————————————————————
先写到这里,下次继续
先写这咯
行为层
结构层
表示层
拿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,所有屏幕都会按比例显示控件,轻松多了吧?
————————————————————————————————————————————————————————————————
先写到这里,下次继续
先写这咯
相关文章推荐
- Android布局layout如何适应不同的分辨率和不同大小的屏幕
- [开发工具] Android下适应各种分辨率——dimens转换工具
- 适应不同分辨率屏幕的问题 android layout
- Android基础——使用Fragment适应不同屏幕和分辨率
- Android各种屏幕的分布率以及自适应各种屏幕的开发研究
- android程序适应各种分辨率
- Android程序对不同手机屏幕分辨率自适应的总结
- C# WinForm窗体及其控件自适应各种屏幕分辨率
- Android程序对不同手机屏幕分辨率自适应的方法
- Android程序对不同手机屏幕分辨率自适应的总结
- Android基础——使用Fragment适应不同屏幕和分辨率
- Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题
- Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题
- Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题
- android各种分辨率和屏幕密度
- Android基础之使用Fragment适应不同屏幕和分辨率(分享)
- Android程序对不同手机屏幕分辨率自适应的方法
- 使GUI适应各种屏幕分辨率
- C# WinForm窗体及其控件自适应各种屏幕分辨率
- 【Android 应用开发】Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题