英文:
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:
<?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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论