Android 布局\当布局位于相对布局内时,权重不起作用

Android 布局\当布局位于相对布局内时,权重不起作用,android,xml,xamarin.android,Android,Xml,Xamarin.android,当线性布局在相对布局内时,布局权重不起作用,问题在于布局权重,即在设计视图中正确显示,但在编译时出现获取错误并停止编译 我的代码是 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout

当线性布局在相对布局内时,布局权重不起作用,问题在于布局权重,即在设计视图中正确显示,但在编译时出现获取错误并停止编译 我的代码是

<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>

很抱歉回复晚了。这会对你有帮助。:)



欢迎使用堆栈溢出!为了帮助人们回答您的问题,您需要更具体地说明错误。请在帖子中加入您从中获得的确切错误(最好使用复制+粘贴以避免转录错误)。首先,在xml中,您没有添加线性布局的方向,第二件事是您已经将权重和添加到线性布局中,然后必须将子视图的高度或宽度设置为0dp以及视图所需的权重(您已经在xml中指定了它)。现在我的问题是你到底想要实现什么??你想把这两个按钮放在屏幕中央吗?我的建议是不要使用fill parent,而是使用match parent,因为两者都做相同的工作,而且在不推荐的情况下也使用fill parent,@pankajkhedkar,谢谢你的回答。实际上,我想设置textview和微调器的宽度比为屏幕宽度的3:7,这是一个位于屏幕中心的布局,在屏幕底部有另一个布局,三个按钮的宽度比为3:4:3。。。。。(我希望你明白了,抱歉我的英语不好)谢谢你的回复。。。我已经接受了你的建议……“首先,在xml中,你没有为线性布局添加方向,第二件事是你已经为线性布局添加了权重和,然后你必须将子视图的高度或宽度设置为0dp,以及视图所需的权重(你已经在xml中指定了它)”谢谢你的回复。。。我已经完成了你的第一次答复,并提出了很好的建议。。。。。我认为在这段代码中,定向在相对布局中是不起作用的:)。是的。方向仅适用于线性布局。不能将方向属性设置为相对布局。
<?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>