当布局在相对布局内时,layout_weight不起作用

时间:2017-01-11 18:12:08

标签: android xml xamarin.android

layout_weight在相对布局中的Linearlayout时不起作用,只有问题在layout_weight中,即在设计视图中正确显示但在编译时获取错误并停止编译 我的代码是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/black"
        android:id="@+id/ll_bookmarkslistad"
        android:weightSum="100"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="30" />
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="70"
            android:layout_marginRight="0.0dp" />
    </LinearLayout>
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

抱歉迟到了。它会帮助你。 :)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@android:color/darker_gray"
        android:layout_centerInParent="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" hello world"
            android:layout_weight="3"/>

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="7"></Spinner>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@android:color/darker_gray"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn1"
            android:layout_weight="3"
            />
        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn2"
            android:layout_weight="4"
            />
        <Button
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="btn3"
            android:layout_weight="3"
            />
    </LinearLayout>
</RelativeLayout>