如何在editText上放置单选按钮

问题描述 投票:0回答:4

这是性别检查按钮。

<EditText
      android:id="@+id/txtSex"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="29dp"
      android:layout_weight="1"
      android:ems="10"
      android:inputType="textPersonName"
      android:text=""/>
android android-layout android-radiobutton
4个回答
4
投票

试试这种方式

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select Gender" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:orientation="vertical">

        <RadioGroup
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:text="Male" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:text="Female" />

        </RadioGroup>

        <View
            android:layout_width="250dp"
            android:layout_height="2dp"
            android:background="@android:color/black" />

    </LinearLayout>
</LinearLayout>

OUTPUT

enter image description here


2
投票

如果你只需要在RadioButton下面加下划线,那么就没有必要把它放在edittext中。只需将视图如下所示,

 <View
    android:layout_width="100dp"
    android:layout_height="1dp"
    android:layout_marginTop="10dp"
    android:background="#ccc" />

0
投票

它看起来像你只想在你的RadioGroup下面划一条线。只需使用高度为1dp的视图和背景颜色。


0
投票

要实现这种类型的UI,需要水平放置两个单选按钮。取后根据底线高度查看设定高度。并将它放在两个单选按钮的垂直位置。

© www.soinside.com 2019 - 2024. All rights reserved.