Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

android - 在ConstraintLayout中将单选按钮向左对齐?(Aligning Radio Buttons to left in ConstraintLayout?)

I can align the Button elements to the left to left using layout_constraintStart_toStartOf and layout_constraintEnd_toStartOf .

(我可以使用layout_constraintStart_toStartOflayout_constraintEnd_toStartOf从左到左对齐Button元素。)

However I'm unable to do that to the radio buttons .

(但是我无法对单选按钮执行此操作 。)

How can I align the radio buttons to left to achieve something like this:

(如何将单选按钮向左对齐以实现以下效果:)

在此处输入图片说明

Here's the layout:

(这是布局:)

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent" >

    <RadioButton
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1" />

    <RadioButton
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2" />
</RadioGroup>
  ask by Learner translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using horizontal orientation in your RadioGroup like below:

(尝试在RadioGroup使用horizontal方向,如下所示:)

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#C8E585"
    app:layout_constraintTop_toTopOf="parent" >

    <RadioButton
        android:id="@+id/btn1"
        android:textSize="18sp"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ColdFusion" />

    <RadioButton
        android:id="@+id/btn2"
        android:textSize="18sp"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Flex" />

    <RadioButton
        android:id="@+id/btn3"
        android:textSize="18sp"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Flash" />
</RadioGroup>

Output:

(输出:) 在此处输入图片说明


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...