【问题标题】:Align a label to text of first RadioButton将标签与第一个 RadioButton 的文本对齐
【发布时间】:2013-04-21 20:39:05
【问题描述】:

我有一个TableLayout 有 2 列:标签和输入字段(SpinnerEditTextRadioGroup)。我想将RadioGroup 的标签与第一个单选按钮的文本完全垂直对齐。文字“Take it”应在红线上。怎么做?有可能吗?

这里是 XML - 剥离到相关的TableRow

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/layoutEditMedication1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:padding="16dp"
  tools:context=".Main" >

  <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/buttons" >

    <TableLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:shrinkColumns="1"
      android:stretchColumns="1" >

      <TableRow style="@style/EditMedicationTableRowT" >

        <TextView
          style="@style/EditMedicationLabel"
          android:layout_gravity="top"
          android:text="@string/i_need_to_take" />

        <RadioGroup
          style="@style/EditMedicationTableRowB"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" >

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

          <RadioButton
            android:id="@+id/radioScheduleSpecial"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/schedule_special" />
        </RadioGroup>
      </TableRow>
    </TableLayout>
  </ScrollView>

</RelativeLayout>

使用的样式有:

<resources>
    <style name="EditMedicationTableRowT">
        <item name="android:paddingTop">8dp</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="EditMedicationTableRowB">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:paddingBottom">8dp</item>
        </style>

    <style name="EditMedicationLabel">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center_vertical</item>
        <item name="android:paddingRight">16dp</item>
        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    </style>
</resources>

我知道我可以制作两个 TableRows 和两个不同的 RadioGroups,每个 RadioButton 一个 RadioButton,然后以编程方式编写一些代码,使它们看起来好像是一个 RadioGroup。但也许有一个简单的解决方案。

API 为 8 及以上。

【问题讨论】:

  • 你能发布你的布局的 XML 吗?
  • 完成......

标签: android alignment baseline


【解决方案1】:

试试这个

<TextView
  style="@style/EditMedicationLabel"
  android:layout_gravity="top"
  android:paddingBottom="0dp"
  android:text="@string/i_need_to_take" />

【讨论】:

  • 抱歉,没有看到您的答案。与此同时,我对树表行进行了处理,并按代码对它们进行了分组(OP 中的最后一段) - 无论如何,谢谢
猜你喜欢
  • 2012-05-02
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
  • 2011-09-14
  • 1970-01-01
  • 2020-06-02
  • 2015-10-16
  • 1970-01-01
相关资源
最近更新 更多