在按钮单选按钮文本按钮、单选、文本

2023-09-05 09:08:09 作者:∫咫尺τiàη涯丆相問

我想创建一个Android的观点是这样的:

I'm trying to create a view in android that looks like:

文本

单选按钮1 ... ...

我认为这是很简单,但至少在布局preVIEW和模拟器我看到的文本单选按钮出现在实际的单选按钮(圆圈)的顶部,见所附截屏。我猜这是一件很琐碎,但我搞砸周围的重力和所有其他设置我能想到的,没有什么。安卓3.1,如果该事项。

I thought it was simple enough but at least in the layout preview and emulator I'm seeing the text for the RadioButton appear on top of the actual radio button (the circle), see the attached screen shot. I'm guessing this is something very trivial but I'm messed around with gravity and every other setting I can think of and nothing. Android 3.1 if that matters.

下面是我的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:background="@color/white"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<TextView android:id="@+id/question_text"
    android:textColor="@color/primary_gray"
    android:layout_width="match_parent"
    android:text="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        android:layout_height="wrap_content"/>

<RadioGroup android:id="@+id/multiple_choice_one_answer_group"
    android:background="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

   <RadioButton
      android:background="@color/primary_gray"
      android:textColor="@color/black"
      android:textSize="10sp"
      android:text="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
</RadioGroup>

</LinearLayout>

截图:

推荐答案

问题是设置背景。如果您删除从单选按钮的背景和保持它在RadioGroup中,有你要找的效果。在一般情况下,设置一个按钮,所有的后台删除按钮的外观;尝试定期按钮,你会看到。这是因为背景的按钮已经设置的东西,而你有一台彩色取代它。

The problem is setting the background. If you remove the background from the RadioButton and keep it on the RadioGroup, it has the effect you're looking for. In general, setting the background of a Button to everything removes the button look; try it on a regular Button and you'll see. This is because the background for a Button is already set to something, and you're replacing it with a flat color.

试试这个来代替:

<RadioGroup android:id="@+id/multiple_choice_one_answer_group"
    android:background="@color/primary_gray"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <RadioButton
        android:textColor="@color/black"
        android:textSize="10sp"
        android:text="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
</RadioGroup>