Abhinav
Abhinav

Reputation: 1015

Android RelativeLayout UI not displayed properly

I am trying to use RelativeView as part of the RecyclerView. But the UI is not displayed properly. Below is the xml which I am using for the relativelayout

<?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>

When I run it in emulator I get below display Emulator view

As I am learning android programing I am not getting what could be the cause that the item are not listed below each item and there is lot of gap coming up between two items.

Upvotes: 1

Views: 63

Answers (2)

Abhijeet Mallick
Abhijeet Mallick

Reputation: 1750

Just change the height of RelativeLayout from match_parent to wrap_content. i.e.

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

Upvotes: 1

Harshal Benake
Harshal Benake

Reputation: 2401

Just update layout height to wrap_content, Refer below code snippet,

<?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="wrap_content"
    android:background="#ff0000"
    android:orientation="vertical">

Upvotes: 1

Related Questions