ภาพซ้ายเป็น ListView
อย่างเดียว
ภาพขวาเป็น ListView
ใน ScrollView
ที่จำกัดความสูงไว้ที่ 300dp แล้วค่อย Scroll ดูไอเทมที่เหลือ
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <ScrollView android:layout_width="match_parent" android:fillViewport="true" android:layout_height="300dp" android:scrollbars="vertical"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" /> </ScrollView> </LinearLayout> |
บรรทัดที่ 14 : ต้องใส่ไม่งั้น ListView
จะเห็นแค่ item เดียว