2017-06-03 6 views
0

リストビューアイテムには次のレイアウトがあります。低解像度デバイスで1dpのパディングが表示されない

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/border" 
    android:orientation="vertical" 
    android:paddingBottom="1dp" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" 
    android:paddingTop="0dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/background_light"> 

     .... 

    </LinearLayout> 

</LinearLayout> 

外側のレイアウト(@drawable/border)の背景は灰色であり、外側のレイアウトのpaddingBottom1dpと内側レイアウトの背景が各リストビュー項目間の灰色の線があり、白色であるからです。

しかし、低解像度(ldpi)デバイスでは、この灰色の線は表示されません。

外部レイアウトのパディングを2dpに変更すると、灰色の線が表示されますが、高解像度のデバイスでは太すぎます。 2dpの代わりに2pxを使用すると、より良い結果が得られます。

低解像度デバイスに灰色の境界線を表示する最適な方法は何ですか?

答えて

1

あなたはあなたのリストビューへのパラメータとしてそれらを追加することにより、分周器と、分周器の高さを設定することができます。

<ListView 
    android:id="@+id/listView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:divider="@drawable/divider" 
    android:dividerHeight="2px"> 
</ListView> 

また、非常に受け入れ答えに見て、代わりにListViewコントロールをRecyclerViewを使用することをお勧めします。 RecyclerView(上記のAndroidサポートライブラリ25.0.0と)に分周器を設定 Android Recyclerview vs ListView with Viewholder

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL); 
recyclerView.addItemDecoration(dividerItemDecoration); 
関連する問題