layout_weight属性图解
16lz
2021-01-26
本文是看了鸿洋视频后的小结:
layout_height的作用:
首先按照声明的尺寸分配,剩余的空间再按照layout_weight进行分配
一平均分配:
代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:background="#e1d611" android:gravity="center" android:text="我是老大我是老大我是老大" android:textColor="#ffffff" android:visibility="gone" /> <TextView android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:background="#09c0f2" android:gravity="center" android:text="我是老二" android:textColor="#ffffff" /> <TextView android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:background="#074bc1" android:gravity="center" android:text="我是老三" android:textColor="#ffffff" android:visibility="gone" /></LinearLayout>
二平均且对齐:
在父控件里添加代码:
android:baselineAligned="false"
三单个分配比例:
在父控件里添加
android:weightSum="2"
代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:baselineAligned="false" android:gravity="center" android:orientation="horizontal" android:weightSum="2"> <TextView android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:background="#09c0f2" android:gravity="center" android:text="我是老二" android:textColor="#ffffff" /></LinearLayout>
更多相关文章
- Android学习――HorizontalScollview水平滚动控件
- android显示图片的两种方法
- android SeekBar 样式大全
- Android(安卓)ListView中 每一项都有不同的布局
- android 世界各国英文简写代码 资源文件
- jQuery Mobile 入门教程
- Android(安卓)说说钟表控件
- 主题:Android(安卓)皮肤apk实现换肤
- 常用布局之相对布局