【发布时间】:2013-04-21 20:39:05
【问题描述】:
我有一个TableLayout 有 2 列:标签和输入字段(Spinner、EditText、RadioGroup)。我想将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