【问题标题】:RadioGroup and TextView in a RelativeLayout - RadioGroup is hiding TextView相对布局中的 RadioGroup 和 TextView - RadioGroup 正在隐藏 TextView
【发布时间】:2015-06-19 15:27:16
【问题描述】:

这就是我想要完成的。 textView 及其下方的 radioButton 组,其中radioButtons 以编程方式添加。我只能得到radioButton 组与radioButtons 而不是textViewradioButton 组占用了布局中的所有空间,textView 不可见。

我在 stackoverflow.com 上查看了许多关于布局格式和显示的帖子,但仍然不知道哪里出错了。

你能帮我解决这个问题吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

    <TextView
        android:id="@+id/sample"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:background="@color/black"
        android:gravity="center"
        android:text="@string/sample"
        android:textColor="@color/white" />

    <RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical" >
    </RadioGroup>

</RelativeLayout>

【问题讨论】:

  • @MarkKeen 的回答是正确的。你应该接受它。
  • 在您的 Radio 组中添加 android:layout_below="@+id/sample" 线路
  • @Harish - 感谢您的回复。我添加了您建议的更改以及修改后的 android:layout_height 到 textView 的“wrap_content”。它现在按预期工作! :)

标签: android android-layout android-radiogroup


【解决方案1】:

从相对布局更改为线性布局。 RelativeLayout 没有“方向”属性,因为事物彼此之间是“相对”的。

【讨论】:

  • 感谢您的回复,但现在什么都没有显示。
  • 更改android:layout_height:。您的ListView 占据了整个屏幕,因为它的高度设置为match_parent
  • @Prera​​kSola - 抱歉,我不明白,应该在哪里更改?在 ListView - android:layout_height 或 Layout android:layout_height。应该改成 wrap_content 吗?
  • 在所有元素中,ListViewTextViewradioGroup,更改height的值。
【解决方案2】:

为后代添加按预期工作的 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height=“wrap_content” >
</ListView>

<TextView
    android:id="@+id/sample"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="20dp"
    android:background="@color/black"
    android:gravity="center"
    android:text="@string/sample"
    android:textColor="@color/white" />

<RadioGroup
    android:id="@+id/radio_group"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:layout_below="@+id/sample”
    android:orientation="vertical" >
</RadioGroup>

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多