Android ListView внутри Fragment не отображает все элементы. Последний отображаемый элемент вырезан из - PullRequest
0 голосов
/ 27 октября 2018

В настоящее время у меня есть ошибка в моем приложении.ListView, который находится внутри фрагмента, не отображает все элементы.Вот снимок экрана:

Снимок экрана ListView

Это должно быть до 50. Но это только до 30 (которое вырезано из).

Вот мой макет строки элемента ListView:

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView_listview_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_16sdp"
            android:layout_marginTop="@dimen/_4sdp"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="@dimen/_18ssp"
            android:gravity="center"
            android:layout_gravity="center_vertical"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </RelativeLayout>
</RelativeLayout>

А вот мой фрагмент с listView:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context=".GeneralFragment">

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

Спасибо:)

Ответы [ 2 ]

0 голосов
/ 27 октября 2018

Во-первых, ваш фрагмент должен выглядеть следующим образом:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context=".GeneralFragment">

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

А макет вашей строки вы можете упростить так:

<?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="wrap_content">

    <TextView
        android:id="@+id/textView_listview_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/_16sdp"
        android:layout_marginTop="@dimen/_4sdp"
        android:text="TextView"
        android:textAlignment="center"
        android:textSize="@dimen/_18ssp"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>

Но, на мой взгляд, лучше определить точную высоту строки вашего предмета, например 48dp. В этом случае ваш макет будет более предсказуемым.

0 голосов
/ 27 октября 2018

Вы можете изменить, как показано ниже:

<ListView
        android:id="@+id/listViewGeneral"
        android:layout_width="match_parent"
        android:layout_height="match_parent" /> //notice this line
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...