Home>

I'm working on an activity that scrolls the list view by modifying the auto-generated scrolling activity.

In the following xml, multiple lines are displayed in ListView, but the header does not shrink neatly like the automatically generated sample.

<? xml version = "1.0" encoding = "utf-8"?><LinearLayout
    xmlns: android = "http://schemas.android.com/apk/res/android"
    xmlns: tools = "http://schemas.android.com/tools"
    xmlns: app = "http://schemas.android.com/apk/res-auto"
    app: layout_behavior = "@ string/appbar_scrolling_view_behavior"
    tools: showIn = "@ layout/activity_display"
    android: layout_width = "match_parent"
    android: layout_height = "match_parent"
    android: orientation = "vertical"
    tools: context = ".DisplayActivity"><LinearLayout
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content"
        android: background = "@ color/colorPrimaryDark"
        android: orientation = "horizontal">    <TextView
            android: layout_width = "30dp"
            android: layout_height = "wrap_content"
            android: textColor = "@ color/header"
            android: gravity = "center"
            android: text = "@ string/title1" />    <TextView
            android: layout_width = "440dp"
            android: layout_height = "wrap_content"
            android: layout_weight = "1"
            android: textColor = "@ color/header"
            android: gravity = "center"
            android: text = "@ string/title2" />    <TextView
            android: layout_width = "120dp"
            android: layout_height = "wrap_content"
            android: layout_weight = "1"
            android: textColor = "@ color/header"
            android: gravity = "center"
            android: text = "@ string/title3" /><TextView
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: layout_weight = "1"
            android: textColor = "@ color/header"
            android: gravity = "center"
            android: text = "@ string/title4" /></LinearLayout><ListView
        android: id = "@ + id/listView"
        android: layout_width = "match_parent"
        android: layout_height = "match_parent"
        android: layout_weight = "1" /></LinearLayout>

So, if you use the following xml, the header will shrink nicely, but only one line will be displayed in ListView.

<? xml version = "1.0" encoding = "utf-8"?><LinearLayout
        android: layout_width = "match_parent"
        android: layout_height = "match_parent"
        android: orientation = "vertical">    <LinearLayout
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: background = "@ color/colorPrimaryDark"
            android: orientation = "horizontal">        <TextView
                android: layout_width = "30dp"
                android: layout_height = "wrap_content"android: textColor = "@ color/header"
                android: gravity = "center"
                android: text = "@ string/title1" />        <TextView
                android: layout_width = "440dp"
                android: layout_height = "wrap_content"
                android: layout_weight = "1"
                android: textColor = "@ color/header"
                android: gravity = "center"
                android: text = "@ string/title2" />        <TextView
                android: layout_width = "120dp"
                android: layout_height = "wrap_content"
                android: layout_weight = "1"
                android: textColor = "@ color/header"
                android: gravity = "center"
                android: text = "@ string/title3" />        <TextView
                android: layout_width = "match_parent"
                android: layout_height = "wrap_content"
                android: layout_weight = "1"
                android: textColor = "@ color/header"
                android: gravity = "center"
                android: text = "@ string/title4" />    </LinearLayout>    <ListView
            android: id = "@ + id/listView"
            android: orientation = "vertical"
            android: layout_width = "match_parent"
            android: layout_height = "0dp"
            android: layout_weight = "1" /></LinearLayout></androidx.core.widget.NestedScrollView>

How can I create a scrolling activity that displays multiple lines in the ListView and shrinks the header nicely?
The Kotlin source code is exactly the same, only xml is changed.