2017-09-15 13 views
0

リスト項目のサイズが、電話機が21+であるかどうかによって異なる問題があります。リスト項目のサイズを一致させる

21より前のデバイスでアイテム間の間隔が同じになるようにするにはどうすればよいですか?

一覧:

<ListView 
    android:id="@android:id/list" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:clipToPadding="false" 
    android:divider="@color/transparent" 
    android:dividerHeight="0dp" 
    android:listSelector="@drawable/list_selector_transparent" 
    android:paddingBottom="1dp" 
    android:paddingTop="3dp" 
    android:scrollbarAlwaysDrawVerticalTrack="false" 
    android:smoothScrollbar="true" 
    android:visibility="visible" /> 

アイテム:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:focusable="false"> 

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_marginBottom="3.5dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginTop="1.5dp" 
    card_view:cardCornerRadius="3dp" 
    card_view:cardElevation="1.7dp"> 
</android.support.v7.widget.CardView> 
</LinearLayout> 

あなたが解決策を知っていれば、私は非常に感謝されます。おかげ

ここでは、私が何を意味するかの写真です:

Picture of the issue

答えて

1

これが原因の影が異なるAPIレベルに描画する方法に起こっています。 21+では、シャドウはの外側にあるに描画されますが、古いレベルでは、の内側に描画されます。ビューの境界です。サポートライブラリは、これらの古いAPIレベルのCardViewにパディングを追加して、影を描く余裕を持っています。

あなたがそれらに関係なく、APIレベルの、同じ動作を作るためにあなたの<android.support.v7.widget.CardView>タグにこの属性を追加することができます。

app:cardUseCompatPadding="true" 

the documentationから:

をロリポップ、CardViewは、その内容にパディングを追加する前にその領域に影を描きます。

また

、あなたはCardViewは、プラットフォーム上で、内側のパディングを追加したい場合はロリポップと同様にした後、あなたはsetUseCompatPadding(boolean)を呼び出し、trueを渡すことができます。

関連する問題