android的布局文件中,权重值weight的作用是什么呢?
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="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="路径"
android:layout_weight="3"
android:id="@+id/txtSearchPath"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="文件名"
android:layout_height="wrap_content"
android:id="@+id/txtSearchFileName"/>
</LinearLayout>
结果为:
现在我们把两个TextView的weight都改成1,那么各自就占布局的1/2了,如图:
http://jingyan.baidu.com/article/5552ef47361ffe518ffbc928.html
简单的说就是所在布局里垂直或者水平方向的比例。两个子控件权重分别为1,则各占屏幕的50%。一个为1,一个为2,则各占三分之一,和三分之二。
就是按比例分配尺寸,不过wrap_content 和 fill_parent时效果是有区别的
http://blog.csdn.net/a7a9a68/article/details/7754544
按比例分配view占据屏幕高或宽的值。