java - 单选按钮未正确对齐

标签 java android eclipse radio-button radio-group

请看下面的代码

    <ScrollView 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"
        tools:context=".Form" >

        <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >




            <TextView
               android:id="@+id/gender"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="Text To Be Displayed"
               android:layout_below="@+id/hipsTxt"
               /> 

            <RadioGroup 
                android:id="@+id/genderRadio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                    android:layout_toRightOf="@+id/gender"
                    android:layout_alignBaseline="@+id/gender"
                >

                <RadioButton
                    android:id="@+id/male"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Male" />

                <RadioButton
                    android:id="@+id/female"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Female" />

            </RadioGroup>


        </RelativeLayout>

</ScrollView>

在这里,我需要将单选按钮显示在 TextView 旁边。但相反,它显示在 TextView 下方!这里有什么问题吗?请帮忙!

PS:Android版本2.3.3

最佳答案

<?xml version="1.0" encoding="utf-8"?>

    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        > 

        <RadioGroup 
            android:id="@+id/genderRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
                android:layout_toRightOf="@+id/gender"

            >

            <RadioButton
                android:id="@+id/male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Male" />

            <RadioButton
                android:id="@+id/female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Female" />

        </RadioGroup>

        <TextView
            android:id="@+id/gender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="Text To Be Displayed" />

    </RelativeLayout>

尝试并更改了您的 xml 内容,现在它已正确对齐,请尝试使用此内容。

关于java - 单选按钮未正确对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14464728/

相关文章:

javascript - React Native 空白 MapView

java - 从 ListView 中的 EditText 获取更新值

java - 可以解决非常基本的 Android 代码中的错误

java - 有效地从 JSONArray 中的所有 JSONObject 获取特定键的值?

android - 未设置为默认时使用我的应用程序进行 NFC 支付

android - 避免在运行时异常的情况下使处理程序线程崩溃?

eclipse - 使用 Eclipse 拒绝项目访问

android - LG G2 vs980 无法被 ADB 设备命令识别(Virtualbox 上的 Win7)

java - 在 Java 中用模 X 实现算术

java - Eclipse Gradle 项目未找到 JUnit 测试