在apkbus上看到的一个问题,之前也遇到过,后来便不了了之。
下面是该问题当时的答案,总觉的有些不太优美。大家有什么好方法么?谢谢。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffe0e8ec" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="20dip" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="20dip" /> </LinearLayout>
附原地址:
http://www.apkbus.com/android-43921-1...
---------------------------------更新-------------------------------------
由于我对android:layout_weight属性的不了解导致了这个问题的出现,经过研究发现android:layout_weight是个很有趣的属性,上面的解决方法非常巧妙。
先来看看什么是android:layout_weight:
Layout weight is used to determine how Android divides up any left over space after the various widgets get all of the space they want.
上面代码中将中间LinearLayout的android:layout_weight设置为1,也就等于中间的LinearLayout占据了剩下的所有空间,很好了解决的layout中高度的问题。
思路1:用RelativeLayout布局
思路2:设置LinearLayout的android:layout_gravity
暂时想到这两个方法,不过目前没在开发环境下,明天试试看是否可行 : )