android 布局文件 layout_weight用法
16lz
2021-01-23
情景一, 布局文件代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:text="TextView1" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="9" android:text="TextView2" /></LinearLayout>
parent view中 android:layout_width="fill_parent" 两个child view:
TextView1 android:layout_weight="1"
TextView2 android:layout_weight="9"
宽度比例效果图如下:
结论:当linearLayout为android:layout_width="fill_parent"子view中android:layout_weigh表示权重比例几分之几的概念,此条件下:TextView1宽度为整个宽度的1/10;
当linearLayout为android:layout_width="wrap_content"子view中android:layout_weigh表示权重比例不起作用没有效果
更多相关文章
- android LinearLayout android:layout_weight 作用,固定比例
- android线性布局之比例
- android 骁龙相机预览宽度方向全屏
- Android imageView图片按比例缩放
- Android TextView使用权重时文字无法居中问题
- 权重
- 关于android LinearLayout的比例布局
- 【android】两个按钮的宽度各占屏幕的一半
- Android新增AppCompatTextView自适应字体大小和文本宽度