android:layout_weight之我见
16lz
2021-12-04
这个属性很重要,使用的时候需要注意:
1.使用过程中如果觉得奇怪,需要检查下控件的layout_height和layout_width是否需要设置为fill_parent
2.两个同一层次的控件使用这个属性的时候,设置的数字大的,所占的比例反而小,例如android:layout_weight = “3”
android:layout_weight = “1”。显示出来的效果是1:3 我也不知道为什么是这样。希望有知道的能知会一下。
3.如果使用LinearLayout垂直摆放3个控件。上下两个控件不设置android:layout_weight。中间的控件设置为android:layout_weight = “1” 则,意思是:除了上下两个控件各自显示各自的大小,剩下的屏幕部分都被中间控件填充
假设中间是一个不确定大小的ListView,则底部的控件不会被遮盖
比如:
<?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" android:orientation="vertical" android:background="#ffffff"><TextView android:layout_width="fill_parent" android:layout_height="50dip" android:gravity="center"android:textSize="20dip"android:textColor="#ffffff" android:background="#33b5e5" android:text="详细记录"/><ListView android:id="@+id/sdc_lv_call_detail" android:layout_width="fill_parent" android:layout_height="wrap_content"android:cacheColorHint="#00000000"android:listSelector="@android:color/transparent"android:background="#ffffff"android:layout_weight="1"android:divider="#cccccc"android:dividerHeight="0.5dip"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <!-- 底部的控件 --> </LinearLayout></LinearLayout>
更多相关文章
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用
- 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
- [置顶] [Android基础]Android中SharedPreferences的使用
- android 使用Intent传递数据之返回结果
- Android(安卓)Layout XML属性
- Android(安卓)数据存储(二) 文件的使用
- Android(安卓)动态设置TextView的drawableLeft等属性