【问题标题】:How to move radio button text below radio button如何将单选按钮文本移动到单选按钮下方
【发布时间】:2019-03-28 22:02:03
【问题描述】:

我尝试过 RadioGroup 按钮。它正在工作,但文本位于单选按钮旁边。我希望文本位于按钮下方。 有没有办法做到这一点或另一种方法来完成同样的任务。

这里是 RadioGroup:

      <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:orientation="horizontal"
        android:weightSum="3"
        >
        <RadioButton
            android:id="@+id/fisrt_imgtoselect"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:background="@drawable/selector_new_order_specifications"
            android:button="@drawable/img_moder_classic"
            android:gravity="center"
            android:layout_weight="1"
            />

        <RadioButton
            android:id="@+id/second_imgtoselect"
            android:button="@drawable/img_classic"
            android:background="@drawable/selector_new_order_specifications"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:gravity="center"
            android:layout_weight="1"
            />

        <RadioButton
            android:id="@+id/third_imgtoselect"
            android:button="@drawable/img_classic"
            android:background="@drawable/selector_new_order_specifications"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:gravity="center"
            android:layout_weight="1"
            />

    </RadioGroup>

【问题讨论】:

  • 您能更详细地描述您的问题吗?你能告诉我你在单选按钮下设置文本的代码吗?
  • 我想做一些用户只能选择这些的照片

标签: android xml radio-button


【解决方案1】:

使用DrawableTop 将drawable 和文本放在下面

<RadioGroup
    android:id="@+id/radios"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_gravity="right"
    android:inputType="text"
    android:orientation="vertical" >

    <RadioButton
        android:id="@+id/first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:drawablePadding="30dp"
        android:drawableTop="@android:drawable/my_icon"
        android:text="first"
        android:textColor="@android:color/black"
        android:textSize="20dip"
        android:gravity="right"/>

    <RadioButton
        android:id="@+id/second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:drawablePadding="30dp"
        android:drawableTop="@android:drawable/my_icon"
        android:text="second"
        android:textColor="@android:color/white"
        android:textSize="20dp"
        android:gravity="right"/>


</RadioGroup>

【讨论】:

  • 它可以工作,但我认为单选按钮不是我想要的,因为当我选择一个按钮时,整个背景都会改变,我想改变图像的背景和文本的颜色
  • 有没有其他方法可以做我想做的事
  • 这是我使用的代码,我问我是否想做一些类似照片允许用户选择其中一个的事情,我应该使用什么正确的方法,谢谢帮助我
  • 当前带有单选组的代码只允许用户选择一个。 radioGroup.setOnCheckedChangeListener 应该告诉你当前选中的单选按钮。
  • 这是对的,但是当我将选择器设置为一个用户单击按钮的整个背景颜色时,更改的按钮包括文本和图像之间的空间,我只想更改文本颜色和框架像上面的照片一样的图像
猜你喜欢
  • 1970-01-01
  • 2019-04-05
  • 2017-05-23
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多