我正在学习layout_weight的时候发现一个很怪异的现象。
都知道layout_weight的权值越小越重要!
可这个应该是相对于相同的layout_width或layout_height来说的,比如两个TextView的layout_height都是fill_parent,或者都是wrap_content时来说的。
如果第1个TextView为fill_parent,第2个TextView为wrap_content,那么结果将会怎么样呢?
于是我写了如下代码:<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
>
<TextView
android:text="111111111111"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
/>
<TextView
android:text="111111111111"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="40"
/>
<TextView
android:text="111111111111"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="40"
/> </LinearLayout>修改代码:删除第3个TextView,将前2个的layout_weight都改为1。
结果如下:
很纳闷!!!
当fill_parent和wrap_content对应的情况下,Android到底是如何根据layout_weight的值来布局的???
希望对此有所研究的前辈能谈谈!!
都知道layout_weight的权值越小越重要!
可这个应该是相对于相同的layout_width或layout_height来说的,比如两个TextView的layout_height都是fill_parent,或者都是wrap_content时来说的。
如果第1个TextView为fill_parent,第2个TextView为wrap_content,那么结果将会怎么样呢?
于是我写了如下代码:<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
>
<TextView
android:text="111111111111"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
/>
<TextView
android:text="111111111111"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="40"
/>
<TextView
android:text="111111111111"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="40"
/> </LinearLayout>修改代码:删除第3个TextView,将前2个的layout_weight都改为1。
结果如下:
很纳闷!!!
当fill_parent和wrap_content对应的情况下,Android到底是如何根据layout_weight的值来布局的???
希望对此有所研究的前辈能谈谈!!
http://hi.csdn.net/space-270533-do-album-picid-709480-goto-down.html
http://hi.csdn.net/space-270533-do-album-picid-709479-goto-up.html
是如果两者一样的width,height,同时有weight存在,那么会按weight来划分;
如果width,height对应,那么,则weight失效?有谁看过源码的,来个深层剖析吧!
你确定见过这个属性???