Search code examples
androidandroid-listviewandroid-arrayadapterandroid-adapterandroid-adapterview

Create scrollable ListView with static items using just XML layout


I want to display a static ListView like Settings > About Phone without creating an Adapter to handle multiple view types etc. What XML layout simulates this exactly? It needs to look exactly like a ListView and have the same divider between items according to the application theme etc.


Solution

  • I used the same XML from the list item templates for each item.

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:overScrollMode="ifContentScrolls" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:divider="?android:attr/dividerHorizontal"
            android:showDividers="middle" >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceListItem"
                android:textStyle="bold"
                android:gravity="center_vertical"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:minHeight="?android:attr/listPreferredItemHeightSmall" />
        </LinearLayout>
    </ScrollView>