我想围绕android布局来包装头部,并且我认为我会从一个简单的例子开始,但由于某种原因它不能正常工作。基于百分比的android布局
我开始时只是将布局分成4块,并使用背景颜色来证明它是按预期工作的。
此代码为伟大工程:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/holo_green_light">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/white">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/holo_orange_light">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/holo_red_light">
</RelativeLayout>
</LinearLayout>
所以我想继续在部分的故障,并在第二届一个,每个填充50%(有效覆盖它)添加两个新的布局。
我已经尝试了LinearLayout和RelativeLayout,我无法获得任何工作。
这里是我现在所拥有的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/holo_green_light">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@android:color/holo_green_dark"
android:layout_alignParentLeft="true" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@android:color/holo_blue_dark"
android:layout_alignParentRight="true" >
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/holo_orange_light">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.25"
android:background="@android:color/holo_red_light">
</RelativeLayout>Layout>
</LinearLayout>
我认为这个问题是在子LinearLayouts的match_parent,但问题是,如果我用WRAP_CONTENT,没有内容,使他们消失。
您应该使用'android:weightSum'属性来实现父级布局。 –
不鼓励嵌套的重量布局。 –
在相对布局中输入一些高度,并添加当前布局的一些屏幕截图。尽量不要使用嵌套布局。 – Codelord