#Android ListViewに枠線を付ける

856 ワード

AndroidはListViewに枠線を付ける
drawableのxmlファイルを新規作成:leftlist_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/leftlist_item_normal"/>
    <stroke android:width="1px" android:color="@color/split_line"/>
</shape>

そしてlistviewに適用
<ListView
    android:id="@+id/left_nav"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:paddingRight="1px"
    android:layout_marginBottom="40dp"
    android:background="@drawable/leftlist_bg>
</ListView>

注意:paddingRight="1px"、この属性を設定しないとlistviewにitemがあるところに枠はありません.
itemのlayout_widht="match_parent"は枠線を覆うのでpaddingRight 1 pxにします.