【问题标题】:How to add Title and Subtitle in android RadioButton?如何在 android RadioButton 中添加标题和副标题?
【发布时间】:2020-04-28 22:48:35
【问题描述】:

我想知道如何在 android 的 RadioButton 中添加字幕。 如下图所示。

带字幕的单选按钮

提前谢谢...

【问题讨论】:

  • 这可能是一个没有文本的RadioButton,旁边有两个TextView 小部件。或者,您可以尝试在RadioButton 文本中使用跨度和换行符来处理格式。使用 Android Studio 中的 Layout Inspector 查看该特定对话框正在使用什么。

标签: java android radio-button


【解决方案1】:

使用不带文字的RadioButton。对于文本使用TextView。检查

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <RadioButton
        android:checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
        <TextView
            android:text="Phone Storage"
            android:textStyle="bold"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <TextView
            android:text="/storage/emulated/0/Xender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

输出:

【讨论】:

    【解决方案2】:

    这可以通过使用带有两个 TextViewRadioButton 轻松完成,正如 CommonsWare 所提到的,但没有任何内置小部件。

    这里是如何实现这一点的。

        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity">
    
    
        <RadioButton
            android:id="@+id/rbSwitch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true" />
    
        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/rbSwitch"
            android:text="Phone Storage"
            android:textColor="@android:color/black"
            android:textSize="16sp" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvTitle"
            android:layout_toRightOf="@id/rbSwitch"
            android:text="/storage/emulated/0/Xender" />
    
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多