Борис Бойко
Борис Бойко

Reputation: 27

Huge distance between listview items

I have a listview with weight sum 4. After including images, I having big padding, but I clear all margins and paddings. All data receiving via adapter from MainActivity. There are screen shot and code below. Thanks for watching and help.

enter image description here

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Пн, сегодня"
        android:id="@+id/title"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:gravity="center" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/icon"
        android:layout_weight="1"
        android:src="@drawable/ic_cloud_queue_24dp"
        android:layout_gravity="center_vertical" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="+17"
        android:id="@+id/genre"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="+9"
        android:id="@+id/year"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_gravity="center_vertical" />

</LinearLayout>

Upvotes: 0

Views: 96

Answers (2)

Jay Rathod
Jay Rathod

Reputation: 11245

Try to use this code.

Changes i have made is added Linear Layout inside Relative Layout with match_parent as Height and Width. Because Linear Layout childs containing match_parent as height so that will affect the list items. That's why i have added new Root Layout and defined all childs as OP.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="4">

        <TextView
            android:id="@+id/title"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Пн, сегодня"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <ImageView
            android:id="@+id/icon"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:src="@drawable/ic_dashboard" />

        <TextView
            android:id="@+id/genre"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:gravity="center"
            android:text="+17"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/year"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:gravity="center"
            android:text="+9"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

</RelativeLayout>

Upvotes: 1

Ivo
Ivo

Reputation: 23179

The LinearLayout the four elements are in have height wrap_content which basically means make it the height the children are. But all 4 children have height match_parent which says just fit in my parent. So this is not very compatible. What I would do is either give all 4 children height wrap_content also, or what maybe better is give the LinearLayout a fixed layout_height

Upvotes: 0

Related Questions