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评论90阅读模式
英文:

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的代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:id="@+id/ll"
  6. android:layout_width="match_parent"
  7. android:layout_height="wrap_content">
  8. <ImageView
  9. android:id="@+id/imageViewID"
  10. android:layout_width="112dp"
  11. android:layout_height="match_parent"
  12. android:layout_weight="1"
  13. app:srcCompat="@android:drawable/ic_menu_today" />
  14. <LinearLayout
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent"
  17. android:layout_weight="1"
  18. android:gravity="center_vertical"
  19. android:orientation="vertical">
  20. <TextView
  21. android:id="@+id/nameTextViewID"
  22. android:layout_width="match_parent"
  23. android:layout_height="wrap_content"
  24. android:text="TextView"
  25. android:textAlignment="center"
  26. android:textSize="18sp" />
  27. <TextView
  28. android:id="@+id/infoTextViewID"
  29. android:layout_width="match_parent"
  30. android:layout_height="wrap_content"
  31. android:text="TextView"
  32. android:textAlignment="center"
  33. android:textSize="18sp" />
  34. </LinearLayout>
  35. </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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:id="@+id/ll"
  6. android:layout_width="match_parent"
  7. android:layout_height="wrap_content">
  8. <ImageView
  9. android:id="@+id/imageViewID"
  10. android:layout_width="112dp"
  11. android:layout_height="match_parent"
  12. android:layout_weight="1"
  13. app:srcCompat="@android:drawable/ic_menu_today" />
  14. <LinearLayout
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent"
  17. android:layout_weight="1"
  18. android:gravity="center_vertical"
  19. android:orientation="vertical">
  20. <TextView
  21. android:id="@+id/nameTextViewID"
  22. android:layout_width="match_parent"
  23. android:layout_height="wrap_content"
  24. android:text="TextView"
  25. android:textAlignment="center"
  26. android:textSize="18sp" />
  27. <TextView
  28. android:id="@+id/infoTextViewID"
  29. android:layout_width="match_parent"
  30. android:layout_height="wrap_content"
  31. android:text="TextView"
  32. android:textAlignment="center"
  33. android:textSize="18sp" />
  34. </LinearLayout>
  35. </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

  1. 尝试将其更改为以下内容:
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:id="@+id/ll"
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content">
  9. <ImageView
  10. android:id="@+id/imageViewID"
  11. android:layout_width="112dp"
  12. android:layout_height="112dp"
  13. app:srcCompat="@android:drawable/ic_menu_today" />
  14. <LinearLayout
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:gravity="center_vertical"
  18. android:orientation="vertical">
  19. <TextView
  20. android:id="@+id/nameTextViewID"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:text="TextView"
  24. android:textAlignment="center"
  25. android:textSize="18sp" />
  26. <TextView
  27. android:id="@+id/infoTextViewID"
  28. android:layout_width="match_parent"
  29. android:layout_height="wrap_content"
  30. android:text="TextView"
  31. android:textAlignment="center"
  32. android:textSize="18sp" />
  33. </LinearLayout>
  34. </LinearLayout>
英文:

Try changing it to this one:

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  3. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  4. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  5. android:id=&quot;@+id/ll&quot;
  6. android:layout_width=&quot;match_parent&quot;
  7. android:layout_height=&quot;wrap_content&quot;&gt;
  8. &lt;ImageView
  9. android:id=&quot;@+id/imageViewID&quot;
  10. android:layout_width=&quot;112dp&quot;
  11. android:layout_height=&quot;112dp&quot;
  12. app:srcCompat=&quot;@android:drawable/ic_menu_today&quot; /&gt;
  13. &lt;LinearLayout
  14. android:layout_width=&quot;match_parent&quot;
  15. android:layout_height=&quot;wrap_content&quot;
  16. android:gravity=&quot;center_vertical&quot;
  17. android:orientation=&quot;vertical&quot;&gt;
  18. &lt;TextView
  19. android:id=&quot;@+id/nameTextViewID&quot;
  20. android:layout_width=&quot;match_parent&quot;
  21. android:layout_height=&quot;wrap_content&quot;
  22. android:text=&quot;TextView&quot;
  23. android:textAlignment=&quot;center&quot;
  24. android:textSize=&quot;18sp&quot; /&gt;
  25. &lt;TextView
  26. android:id=&quot;@+id/infoTextViewID&quot;
  27. android:layout_width=&quot;match_parent&quot;
  28. android:layout_height=&quot;wrap_content&quot;
  29. android:text=&quot;TextView&quot;
  30. android:textAlignment=&quot;center&quot;
  31. android:textSize=&quot;18sp&quot; /&gt;
  32. &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:

确定