android布局权重%
问题描述:
我正在尝试弄乱Android布局权重属性. 我想要一个带有"3个子布局"的垂直布局,第一个占据25%的空间,第二个占据50%的空间,最后一个占据25%的空间.当我尝试添加到最后一个布局时,一切都无法正常工作.这些布局的权重分别是多少?
I am trying to messing around with the Android layout weight attributes. I want a vertical layout with "3 child layouts" The first will take 25% of the space, the second 50%, and the last 25% of the space. When I try to add to the last layout, everything just not working. What should be the weight for each of these layouts?
我获得了权重属性,可以仅使用2种布局/元素并理解其工作原理,但是当我尝试使用3种布局/元素时,我遇到了问题.
I get the weight attributes to work fine with just 2 layouts/elements and understand how it works but when I try with 3 I get a problem.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="25" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="50" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="25" >
</LinearLayout>
</LinearLayout>
答
尝试使用此代码.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<LinearLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="25">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="50" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="25">
</LinearLayout>
</LinearLayout>