Android RelativeLayout UI 显示不正确

标签 android android-recyclerview android-relativelayout

我正在尝试将 RelativeView 用作 RecyclerView 的一部分。但是 UI 显示不正确。下面是我用于相对布局的 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:orientation="vertical">

    <CheckBox
        android:id="@+id/list_item_crime_solved_check_box"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:padding="4dp"/>

    <TextView
        android:id="@+id/list_item_crime_title_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/list_item_crime_solved_check_box"
        android:textStyle="bold"
        android:padding="4dp"
        tools:text="Crime Title"/>

    <TextView
        android:id="@+id/list_item_crime_date_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/list_item_crime_solved_check_box"
        android:layout_below="@id/list_item_crime_title_text_view"
        android:padding="4dp"
        tools:text="Crime Date"/>

</RelativeLayout>

当我在模拟器中运行它时,我得到以下显示 Emulator view

因为我正在学习 android 编程,所以我不知道是什么原因导致该项目未在每个项目下方列出,并且两个项目之间存在很大差距。

最佳答案

只需将 RelativeLayout 的高度从 match_parent 更改为 wrap_content。即

<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="wrap_content">

关于Android RelativeLayout UI 显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39054258/

相关文章:

Android RelativeLayout 对齐关注

android - 单击时不要将按钮置于前台

Android:如何在点击不可见按钮时调用函数?

android - 将 REST 服务与 Android 应用程序同步

java - 将时区应用于 Date 对象

android - 全屏来电图片和全屏来电显示

java - Android RecyclerView添加和删除项目

java - 从工作线程使用 RecyclerView.setAdapter

android - 当我们滚动时,RecyclerView 如何从 Adapter 获取 1 个额外的 View

android - 根据 ImageButton drawable 调整按钮宽度