【问题标题】:How to put a radiobutton on the most right如何在最右边放置一个单选按钮
【发布时间】:2011-04-22 00:44:57
【问题描述】:

我试图在垂直排列的前两个文本视图中进行布局,然后是文本,然后在最右侧使用线性布局放置一个单选按钮。然而,即使我输入了 '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>

【问题讨论】:

    标签: android radio-button gravity


    【解决方案1】:

    右侧对齐单选按钮:

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

    【讨论】:

      【解决方案2】:

      你应该把radioButton的宽度设为

      android:layout_width="wrap_content"

      并添加

      android:layout_weight="1"

      到 TwoLineListItem 和 TextView

      【讨论】:

      • 非常感谢!:D 如果您不介意,请告诉我 layout_weight 是如何工作的?
      • 通过赋予所有三个权重将平均划分屏幕宽度......仍然不清楚然后检查开发者网站。他们提供了很好的文档。
      【解决方案3】:

      你正在使用 android:layout_gravity="right"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-01
        • 2021-03-11
        • 2021-11-24
        • 2017-01-13
        相关资源
        最近更新 更多