Android 为什么这项权利不起作用?

Android 为什么这项权利不起作用?,android,android-layout,layout,textview,android-relativelayout,Android,Android Layout,Layout,Textview,Android Relativelayout,我是android开发的新手,在构建布局时遇到了问题。我有一个包含文本视图的相对布局和一个包含两个复选框的线性布局。我希望文本视图显示在左侧,线性布局显示在与边缘齐平的线性布局的右侧。当前,textview和linearlayout显示在彼此的顶部。非常感谢您的帮助 <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"

我是android开发的新手,在构建布局时遇到了问题。我有一个包含文本视图的相对布局和一个包含两个复选框的线性布局。我希望文本视图显示在左侧,线性布局显示在与边缘齐平的线性布局的右侧。当前,textview和linearlayout显示在彼此的顶部。非常感谢您的帮助

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:text="Rotated Shelf:           " 
                android:layout_gravity="center_vertical"/>

            <LinearLayout
                android:id="@+id/rotated"
                android:layout_width="match_parent"
                android:layout_height="32dp"                   
                android:layout_alignParentRight="true">                  

                <CheckBox
                    android:id="@+id/rotatedshelfYES"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Yes"
                    android:layout_toLeftOf="@+id/rotatedshelfNO"
                     />

                <CheckBox
                    android:id="@+id/rotatedshelfNO"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingRight="75dp"
                    android:text="No"
                    android:layout_alignParentRight="true" />
            </LinearLayout>
        </RelativeLayout>

像这样尝试您的
文本视图
线性布局中编写
并设置
android:layou-weight=”“
它工作得很好

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/rotated"
        android:layout_width="match_parent"
        android:layout_height="32dp"
        android:layout_alignParentRight="true" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight=".5"
            android:paddingLeft="5dp"
            android:text="Rotated Shelf:           " />

        <CheckBox
            android:id="@+id/rotatedshelfYES"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="Yes" />

        <CheckBox
            android:id="@+id/rotatedshelfNO"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".25"
            android:text="No" />
    </LinearLayout>
</RelativeLayout>


LinearLayout
添加
android:layout\u toRightOf=“@+id/textView2”
如果要将文本视图的右边缘与线性布局的左边缘对齐(即,文本视图位于LinearLayout的左侧),您应该使用

android:layout_toLeftOf="@+id/rotated"

在您的TextView属性中。

使用您必须将android:layout\u width in linear layout设置为wrap\u content not match\u parent,因为当我们想要将宽度/高度设置为width/height作为小部件/容器的父级,而wrap\u content as name suggest只需要空间来编写视图/容器的标题时,就使用了match\u parent,不需要额外的空间。

部分问题在于线性布局设置为
宽度:“匹配父项”
,这意味着它将是整个屏幕的大小。尝试将其更改为
“wrap_content”
,这样可以使其刚好足够大,以适合复选框,从而为其留出空间,以便快速移动到右侧边缘。