2014-03-29 37 views
0

我试图使用layout_weight并与水平方向的线性布局layout_width。线性布局包含1个TextView和2个RadioButton(在RadioButtonGroup中)。我希望TextView填充RadioButtons左侧的空间,并始终保持RadioButtons在屏幕上右对齐。因此,无论文本的数量如何,TextView都应占用空间,以便RadioButton始终是右对齐的。 LinearLayout在ListView中使用,在列表中有多行。的Android Layout_Weight为固定宽度不工作

不幸的是,TextView的是,尽管指定机器人包装内容:layout_width = “0dp” 和机器人:权重= “1”。而RadioButtons并没有很好地排列在右边。
这里的图像

](http://postimg.org/image/549k28f4t/)

这里的LinearLayout中的XML。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:scrollbarAlwaysDrawVerticalTrack="false" > 

    <TextView 
     android:id="@+id/jokeTextView" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="match_parent" 
     android:gravity="center_vertical"/> 

    <RadioGroup 
     android:id="@+id/ratingRadioGroup" 
     android:layout_width="35dp" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:orientation="vertical" > 

     <RadioButton 
      android:id="@+id/likeButton" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:button="@drawable/like" 
      android:gravity="right"/> 

     <RadioButton 
      android:id="@+id/dislikeButton" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:button="@drawable/dislike" 
      android:gravity="right"/> 

    </RadioGroup> 

</LinearLayout> 

我也尝试过设置RadioButton android:layout_width =“wrap_content”,它也没有工作。任何帮助,将不胜感激。

+0

尝试'机器人:重力= “fill_horizo​​nal”'在'LinearLayout'。我认为问题在于'LinearLayout'缩小到外部容器内的最小尺寸。 – Gene

回答

1

试试这个..

我猜你的ListView宽度wrap_content改变它match_parent并尝试

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
+0

谢谢你做到了! – Todd

0

问题是与你的列表视图。有与项目布局

没有问题,如果你想在一个侧面,一个在其他布局

更改的ListView

android:layout_width="match_parent"" 
0

,使用的RelativeLayout:alignParentRight /左。