C
C
cepprice2019-02-03 19:29:13
Android
cepprice, 2019-02-03 19:29:13

How to limit the height of a ListView?

How to make ListView have layout_height= h1 (see screenshot).5c5716ac5e90a745915997.png

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".AlarmsActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimaryDark"
        android:text="@string/app_name"
        android:textColor="@color/colorAccent"
        android:textAllCaps="true"
        android:padding="10dp"/>

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

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/background_orange"
            android:scaleType="centerCrop"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:orientation="horizontal"
        android:background="@color/colorPrimary"
        android:padding="8dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/add_new_alarm"
            android:textColor="@color/colorAccent"
            android:textAllCaps="true"
            android:textSize="12sp"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_add_circle_outline_black_24dp"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>

    <include layout="@layout/view_dividing_line"/>



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary">

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

        <include layout="@layout/view_dividing_line"
            android:id="@+id/bottom_dividing_line"
            android:layout_width="match_parent"
            android:layout_height="10dp"
            android:layout_below="@id/list_view_alarms"/>

        <View
            android:layout_height="40dp"
            android:layout_width="match_parent"
            android:background="@color/colorPrimary"
            android:layout_alignParentBottom="true" />

    </RelativeLayout>

</LinearLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tiberal, 2019-02-04
@Tiberal

RecyclerView can layout_height = "wrap_content", ListView can't(count by hands).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question