Android:如何垂直对齐:将单选按钮添加到多行文本?

时间:2014-07-08 15:40:11

标签: android android-radiogroup

如您所见,我有一个简单的RadioGroup及其选项。

<RadioGroup
    android:id="@+id/radio_report_problems"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="20dp" >

    <RadioButton
        android:id="@+id/radiooption_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/report_problem_rd_opt_1" />

    <RadioButton
        android:id="@+id/radiooption_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/report_problem_rd_opt_2" />

    .....

</RadioGroup>

我的问题是子弹位于文本中间,而不是从第一行开始

printscreen

不使用tableView或linearLayout,是否有一种简单的方法可以使用仅限RadioGroup 实现此目的?

谢谢。

3 个答案:

答案 0 :(得分:3)

您可以扩展RadioButton并覆盖onDraw方法以绘制与文本顶部对齐的按钮。用于绘制该按钮的代码实际上位于CompoundButton内(RadioButton从此延伸),因此应该是如何绘制按钮的起点。 Source

就我个人而言,我并不认为按钮与中心对齐有什么问题,但这就是重点。

答案 1 :(得分:0)

我用过

android:gravity="top"

并且有效

看到这个: enter image description here

答案 2 :(得分:-2)

设置重力顶部|底部的单选按钮

radioButton.setGravity(Gravity.TOP | Gravity.BOTTOM);
相关问题