2017-09-15 18 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添加填充以便有空间绘制阴影。

可以将此属性添加到您的<android.support.v7.widget.CardView>标签,使他们具有相同的行为,无论API级别:

app:cardUseCompatPadding="true" 

the documentation

棒棒堂之前,CardView添加填充其内容并为该区域绘制阴影。

或者,如果你想CardView对平台棒棒堂和后加内垫,以及,你可以调用setUseCompatPadding(布尔),并通过真实的。