【发布时间】:2016-04-08 17:44:54
【问题描述】:
我有三个收音机组,每个组里面都有两个按钮。从这张图片可以看出:http://imgur.com/JQJ0a7A [1] ,按钮在android studio中都排得很整齐。但是,当我在 VM 中运行应用程序时,我最终会得到:http://imgur.com/nKdth41 [2]。
任何想法为什么会发生这种情况?提前感谢您的帮助。
xml代码:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="onerepmax.reversepyramid.RPworkout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/workoutButton"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:width="175dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/warmupButton"
android:id="@+id/button3"
android:width="175dp"
android:layout_alignBottom="@+id/button"
android:layout_toRightOf="@+id/button"
android:layout_toEndOf="@+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/liftText"
android:layout_marginTop="50dp"
android:layout_below="@+id/button"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="@+id/weightText1"
android:layout_marginRight="36dp"
android:layout_marginEnd="36dp"
android:layout_alignTop="@+id/repText1"
android:layout_toLeftOf="@+id/repText1"
android:layout_toStartOf="@+id/repText1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="@+id/repText1"
android:layout_marginTop="66dp"
android:layout_below="@+id/liftText"
android:layout_alignLeft="@+id/liftText"
android:layout_alignStart="@+id/liftText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="@+id/weightText2"
android:layout_alignTop="@+id/weightText1"
android:layout_marginTop="70dp"
android:layout_alignLeft="@+id/weightText3"
android:layout_alignStart="@+id/weightText3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="@+id/repText2"
android:layout_alignTop="@+id/repText1"
android:layout_alignLeft="@+id/repText1"
android:layout_alignStart="@+id/repText1"
android:layout_marginTop="70dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="@+id/weightText3"
android:layout_alignTop="@+id/weightText2"
android:layout_marginTop="70dp"
android:layout_alignLeft="@+id/weightText1"
android:layout_alignStart="@+id/weightText1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="@+id/repText3"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/repText1"
android:layout_alignStart="@+id/repText1"
android:layout_alignTop="@+id/repText2"
android:layout_marginTop="70dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nextButton"
android:id="@+id/nextButton"
android:layout_marginBottom="39dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="@+id/button3"
android:layout_alignEnd="@+id/button3"
android:layout_above="@+id/weightText3"
android:orientation="horizontal"
android:layout_toRightOf="@+id/nextButton"
android:layout_toEndOf="@+id/nextButton"
android:layout_below="@+id/liftText"
android:id="@+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="59dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:checked="false"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="59dp"
android:buttonTint="#d32323"/>
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="@+id/radioGroup"
android:layout_alignEnd="@+id/radioGroup"
android:layout_below="@+id/weightText1"
android:layout_alignBottom="@+id/weightText3"
android:orientation="horizontal"
android:layout_toEndOf="@+id/button"
android:layout_toRightOf="@+id/button">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton3"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="45dp"
android:layout_marginLeft="45dp"
android:layout_marginStart="45dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton4"
android:checked="false"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="45dp"
android:buttonTint="#d32323"/>
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignRight="@+id/radioGroup"
android:layout_alignEnd="@+id/radioGroup"
android:layout_below="@+id/repText2"
android:layout_above="@+id/nextButton">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton5"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="45dp"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton6"
android:checked="false"
android:layout_marginRight="37dp"
android:layout_marginEnd="37dp"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="45dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
【问题讨论】:
-
共享此布局的完整 xml,显示没有它们实际对齐的元素的单选组并不是很有帮助
-
好的,已编辑以包含完整的 xml 文件。
-
对于没有正确使用单选组的初学者,您可以使用 RadioButton 提供的文本元素大大改进您的布局
-
我无法想象它会如何工作。在使用提供的文本元素时,您将如何获得我现在拥有的 UI?此外,我不认为没有文本意味着我使用错误。
标签: android android-studio radio-button radio-group