当前位置:编程学习 > wap >>

Android 的LinearLayout 布局--求助!!!!!!

我正在学习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>

[img=http://hi.csdn.net/space-270533-do-album-picid-709479.html][/img]

修改代码:删除第3个TextView,将前2个的layout_weight都改为1。
结果如下:
[img=http://hi.csdn.net/space-270533-do-album-picid-709480.html][/img]

很纳闷!!!
当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 --------------------编程问答-------------------- 怎么图片显示不了的
[img=http://hi.csdn.net/space-270533-do-album-picid-709479-goto-down.html][/img] --------------------编程问答-------------------- 设置了layout_weight的控件,控件间layout_width layout_height的赋值不匹配会出现些让人意外的情况,求楼下解释... --------------------编程问答-------------------- 根据结果来看:
是如果两者一样的width,height,同时有weight存在,那么会按weight来划分;
如果width,height对应,那么,则weight失效?

有谁看过源码的,来个深层剖析吧! --------------------编程问答-------------------- 即使要看源码,也要先找到源码相对应的部分,希望有看过的指点一下。 --------------------编程问答-------------------- android:layout_weight="3"
你确定见过这个属性??? --------------------编程问答-------------------- 你想实现什么功能?不要使用android:layout_width="fill_parent"!
补充:移动开发 ,  Android
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,