android:layout_width没有百分比的设置方法 但可以通过android:layout_weight的方式实现百分比

android:layout_width没有百分比的设置方法。

但可以通过android:layout_weight的方式实现百分比

比如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<LinearLayout
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
     >
      <TextView
          android:layout_width="wrap_content"//宽度设为wrap_content自适应
          android:layout_height="fill_parent"
          android:layout_weight="1"  //这里所占比例是所有LinearLayout下组件自适应后剩余宽度比例为1/(1+2+3)
          android:background="#aa0000"
          android:gravity="center"
          android:text="1"/>
      <TextView
          android:layout_width="wrap_content"//宽度设为wrap_content自适应
          android:layout_height="fill_parent"
          android:layout_weight="2"//这里所占比例是所有LinearLayout下组件自适应后剩余宽度比例为2/(1+2+3)
          android:background="#00aa00"
          android:gravity="center"
          android:text="1"/>
      <TextView
          android:layout_width="wrap_content"//宽度设为wrap_content自适应
          android:layout_height="fill_parent"
          android:layout_weight="3"//这里所占比例是所有LinearLayout下组件自适应后剩余宽度比例为3/(1+2+3)
          android:background="#0000aa"
          android:gravity="center"
          android:text="1"/>
  </LinearLayout>
 
posted @ 2018-03-19 22:45  sky20080101  阅读(676)  评论(0)    收藏  举报