Как сделать ListView изменяемого размера? - PullRequest
0 голосов
/ 13 февраля 2020

Изображение 1

enter image description here

Изображение 2

enter image description here

Как сделать ListView изменяемым размером?

Это ListView в порядке. OK ListView 1 Picture

enter image description here

OK ListView 2 Picture

enter image description here

Я перепробовал все макеты. Это не помогает.

У меня есть контейнер фрагментов:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@color/yellow"
    tools:context=".MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/fragmentsContainer"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:menu="@menu/menu"
        android:id="@+id/bottomNavigation"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

ОК. Макет - это макет поиска:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/yellow"
    android:id="@+id/searchAndListViewContainer"
    android:orientation="vertical">

    <SearchView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorOfSearchView" />

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

</LinearLayout>

неадекватный макет:

<?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:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/darkGreen">

    <ListView
        android:id="@+id/musicListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

</LinearLayout>

Как видите Java Код изменит внутреннее содержимое контейнера Fragments. Два фрагмента практически идентичны. В чем проблема?

1 Ответ

0 голосов
/ 13 февраля 2020
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/lv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/tv_footer"
            android:layout_below="@+id/tv_header" />

        <TextView
            android:id="@+id/tv_footer"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="#ff0000"
            android:gravity="center"
            android:text="Footer" />

        <TextView
            android:id="@+id/tv_header"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="#00ff00"
            android:gravity="center"
            android:orientation="vertical"
            android:text="Header" />        

   </RelativeLayout>

Вы можете сделать это несколькими способами. здесь вы можете установить свой собственный вид заголовка и нижнего колонтитула.

...