android自适应屏幕
2017-04-16 08:37
176 查看
android xml的布局要自适应各种屏幕的话,需要使用opx布局,在app/res/values/styles.xml中增加如下的代码
【1】 4中必须知道的android屏幕自适应解决方案
<!-- 全屏幕拉伸--> <style name="layout_full"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">fill_parent</item> </style> <!-- 固定自身大小--> <style name="layout_wrap"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style> <!-- 横向分布--> <style name="layout_horizontal" parent="layout_full"> <item name="android:layout_width">0px</item> </style> <!-- 纵向分布--> <style name="layout_vertical" parent="layout_full"> <item name="android:layout_height">0px</item> </style>并在main.xml中增加如下的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/layout_full" android:orientation="vertical"> <LinearLayout style="@style/layout_vertical" android:layout_weight="1" android:orientation="horizontal"> <View style="@style/layout_horizontal" android:background="#aa0000" android:layout_weight="1"/> <View style="@style/layout_horizontal" android:background="#00aa00" android:layout_weight="4"/> <View style="@style/layout_horizontal" android:background="#0000aa" android:layout_weight="3"/> <View style="@style/layout_horizontal" android:background="#aaaaaa" android:layout_weight="2"/> </LinearLayout> <LinearLayout style="@style/layout_vertical" android:layout_weight="2" android:orientation="vertical"> <View style="@style/layout_vertical" android:background="#ffffff" android:layout_weight="4"/> <View style="@style/layout_vertical" android:background="#aa0000" android:layout_weight="3"/> <View style="@style/layout_vertical" android:background="#00aa00" android:layout_weight="2"/> <View style="@style/layout_vertical" android:background="#0000aa" android:layout_weight="1"/> </LinearLayout> </LinearLayout>通过opx和weight来成比例地显示内容
【1】 4中必须知道的android屏幕自适应解决方案
相关文章推荐
- android 屏幕自适应问题
- android自适应屏幕方向和大小
- Android 屏幕自适应方向尺寸与分辨率
- Android自适应屏幕大小和layout布局(横屏|竖屏)
- android自适应屏幕方向和大小
- android自适应屏幕方向和大小
- android 如何做屏幕自适应, 在不可调整分辨率的情况下(据说某些新出的机器可调,也就是说大部分机器分辨率都不可调的)
- Android自适应屏幕大小和layout布局
- [android UI]应用程序自适应屏幕大小
- android edittext 键盘弹出屏幕自适应
- android自适应滑动键盘产生的屏幕尺寸变化
- Android自适应屏幕方向、大小和分辨率
- [android UI]应用程序自适应屏幕大小
- Android自适应屏幕大小和layout布局
- android自适应屏幕方向和大小
- Android: android自适应屏幕方向和大小
- [android UI]应用程序自适应屏幕大小
- Android自适应屏幕大小和layout布局
- Android自适应屏幕大小和layout布局(横屏|竖屏)
- android 界面自适应屏幕尺寸相关