0

我已经创建了一个自定义列表视图,但是当我运行代码时,我得到每个屏幕 1 行。我已经将父布局的布局宽度和高度分别放在listview_row.xmlasmatch_parentwrap_Content

这是代码listview_row.xml

<?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/ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageViewID"
        android:layout_width="112dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        app:srcCompat="@android:drawable/ic_menu_today" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:id="@+id/nameTextViewID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/infoTextViewID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="18sp" />
    </LinearLayout>
</LinearLayout>

但在所有其余编码之后,我得到了输出,因为 我只能看到一个屏幕第二行远低于屏幕

在这里,我向下滚动了一点并显示

任何人都可以帮助我,以便像普通的 listView 一样显示行,而不是每页显示 1 行?

我是新手,提前感谢。

4

1 回答 1

0

尝试将其更改为这个:

<?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/ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageViewID"
        android:layout_width="112dp"
        android:layout_height="112dp"
        app:srcCompat="@android:drawable/ic_menu_today" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="vertical">

    <TextView
        android:id="@+id/nameTextViewID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textAlignment="center"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/infoTextViewID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textAlignment="center"
        android:textSize="18sp" />
</LinearLayout>
于 2020-10-11T23:36:40.180 回答