2013-04-09 132 views
0

我是Android开发的小菜鸟,我在构建布局时遇到问题。我有一个包含textview和包含两个复选框的线性布局的相对布局。我希望textView显示在左侧,线性布局显示在线性布局的右侧与边缘齐平。目前,textview和linearlayout显示在彼此之上。任何帮助是极大的赞赏。为什么alignParentRight不能正常工作?

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

部分是你的LinearLayout设置为'宽:“match_parent”'这意味着它将会是屏幕的全尺寸。尝试将其更改为“wrap_content”,该值应该足够大以适应复选框,该复选框应该有足够空间向右边移动。 – FoamyGuy 2013-04-09 13:57:13

回答

1

尝试这样你textview写在linear-layout并设置android:layout_weight=""它的LinearLayout工作不错

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

添加android:layout_toRightOf="@+id/textView2"

0

如果你要调整你的TextView的右边缘与LinearLayout的左边缘(即LinearLayout左边的TextView)应该使用

android:layout_toLeftOf="@+id/rotated" 

在您的TextView属性中。

0

使用你必须设置android:layout_width在线性布局等于wrap_content不match_parent因为match_parent用于当我们想要等于宽度/高度作为部件/容器的父母和wrap_content名称建议只需要空间仅用于写视图/容器的标题,不需要额外的空间。你的问题的