Android中元素按比例布局
16lz
2021-01-26
为了创建比例大小的子View,可以将LinearLayout的宽度和高度设为fill_parent, 而将子View的宽度或是高度设为0,然后为子View设置不同权重(weight) ,这样子View的大小就会权值成比例。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/orange" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/blue" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/coffee" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/yellow" /></LinearLayout>
效果图:
更多相关文章
- Android开发学习之View测量的内置常用方法
- Android(安卓)获取标题栏以及状态栏的高度
- android iphone手机分辨率尺寸比例整理
- Android根据屏幕宽度,按比例缩放图片
- Android标题栏渐变色,沉寂式状态栏
- [转]Android(安卓)获取当前Activity的屏幕截图
- Android中判断状态栏是否存在
- 高度状态栏Android获取状态栏的高度高度状态栏
- android中各种height和width总结