2011-04-22 33 views
2

我试图做一个垂直布局的前两个文字布局,然后是文本,然后在最右边用linearlayout放置一个单选按钮。然而,即使我输入'android:gravity =“right”',它也不会移动,只是粘在那里。如果有人有想法,你能帮我吗?以下是我的代码。如何把最右边的单选按钮


<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <TwoLineListItem android:id="@+id/twoLineListItem1" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
     <TextView android:id="@+id/textView1" 
       android:text="TextView" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
     <TextView android:id="@+id/textView2" 
       android:text="TextView" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:paddingTop="30px"/> 
    </TwoLineListItem> 
    <TextView android:text="TextView" 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:paddingTop="10px"/> 

    <RadioButton android:id="@+id/radioButton1" 
      android:gravity="right" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
</LinearLayout> 

回答

2

你应该把单选按钮的宽度

的android:layout_width = “WRAP_CONTENT”

而且添加

机器人:layout_weight = “1”

既TwoLineListItem和TextView的

+0

非常感谢你!d如果你不介意的话,会你请让我知道layout_weight是如何工作的? – June 2011-04-22 01:18:03

+1

通过给所有三个重量将平分屏幕宽度.....仍然不清楚,然后检查开发人员网站。他们提供良好的文档。 – 2011-04-22 01:29:15

0

你是使用的Android版本:layout_gravity = “右”

3

单选按钮右侧对齐:

<RadioButton 
        android:id="@+id/radio0" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:background="@null" 
        android:button="@null" 
        android:checked="true" 
        android:drawableRight="@drawable/presets_sel" 
        android:padding="12dp" 
        android:text="RadioButton 1" /> 
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/right_arrow_h" android:state_checked="true"/> 
    <item android:drawable="@drawable/right_arrow_h" android:state_pressed="true"/> 
    <item android:drawable="@drawable/right_arrow"></item> 

</selector> 
相关问题