Why am I getting a different Sized list row while using a CustomListAdapter even though i tried giving a specific value to the custom list row

huangapple go评论69阅读模式
英文:

Why am I getting a different Sized list row while using a CustomListAdapter even though i tried giving a specific value to the custom list row

问题

这是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一样显示行,而不是每页显示一行?

我对此不太了解,提前谢谢。

英文:

I have created a custom listView but when I run the code I get 1 row per screen. I have put the layout width and height of the parent layout in the listview_row.xml as match_parent and wrap_Content respectively.

this is the code for the 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>

but after all rest coding, I get the output as
i can see only one row a screen the 2nd row is far below

here I have scrolled a bit down and showed

Can anyone help me with this such that to display rows like a normal listView instead of getting 1 row per page?

I am new to this and thanks in advance.

答案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>
    </LinearLayout>
英文:

Try changing it to this one:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:id=&quot;@+id/ll&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;wrap_content&quot;&gt;

    &lt;ImageView
        android:id=&quot;@+id/imageViewID&quot;
        android:layout_width=&quot;112dp&quot;
        android:layout_height=&quot;112dp&quot;
        app:srcCompat=&quot;@android:drawable/ic_menu_today&quot; /&gt;

    &lt;LinearLayout
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:gravity=&quot;center_vertical&quot;
        android:orientation=&quot;vertical&quot;&gt;

    &lt;TextView
        android:id=&quot;@+id/nameTextViewID&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;TextView&quot;
        android:textAlignment=&quot;center&quot;
        android:textSize=&quot;18sp&quot; /&gt;

    &lt;TextView
        android:id=&quot;@+id/infoTextViewID&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;TextView&quot;
        android:textAlignment=&quot;center&quot;
        android:textSize=&quot;18sp&quot; /&gt;
&lt;/LinearLayout&gt;

</LinearLayout>

huangapple
  • 本文由 发表于 2020年10月11日 23:52:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/64306041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定