Android支持Library的CardView在不同设备上的不同结果
Different results of Android Support Library's CardView on different devices
玩 Android Support Library
v7 小部件 CardView
我在 Galaxy S4 和 Nexus 4 设备上看到不同的结果。具有以下布局:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
card_view:cardCornerRadius="7dp"
card_view:cardElevation="12dp">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true">
<TextView
android:id="@+id/txtExample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_messages" />
</ScrollView>
</android.support.v7.widget.CardView>
我得到了这些结果:
连结 4 (5.0.1):
三星 Galaxy S4 (4.4.2):
Nexus 上的那个好像是用它的边距计算 View,然后在外面画阴影。另一方面,三星似乎应用边距,然后在内部绘制阴影,直到它到达计算的视图边界。
我是不是漏掉了什么?
你所有的观察都是正确的:)
官方都解释的很好documentation of CardView:
Before L, CardView adds padding to its content and draws shadows to
that area. This padding amount is equal to maxCardElevation + (1 -
cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 -
cos45) * cornerRadius on top and bottom.
和:
Note that, if you specify exact dimensions for the CardView, because
of the shadows, its content area will be different between platforms
before L and after L. By using api version specific resource values,
you can avoid these changes. Alternatively, If you want CardView to
add inner padding on platforms L and after as well, you can set
setUseCompatPadding(boolean) to true.
如那里所述-您应该只使用 setUseCompatPadding (true)
然后在两者上使用外部填充:L 和 pre-L 将一样。
玩 Android Support Library
v7 小部件 CardView
我在 Galaxy S4 和 Nexus 4 设备上看到不同的结果。具有以下布局:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
card_view:cardCornerRadius="7dp"
card_view:cardElevation="12dp">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true">
<TextView
android:id="@+id/txtExample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_messages" />
</ScrollView>
</android.support.v7.widget.CardView>
我得到了这些结果:
连结 4 (5.0.1):
三星 Galaxy S4 (4.4.2):
Nexus 上的那个好像是用它的边距计算 View,然后在外面画阴影。另一方面,三星似乎应用边距,然后在内部绘制阴影,直到它到达计算的视图边界。
我是不是漏掉了什么?
你所有的观察都是正确的:)
官方都解释的很好documentation of CardView:
Before L, CardView adds padding to its content and draws shadows to that area. This padding amount is equal to maxCardElevation + (1 - cos45) * cornerRadius on the sides and maxCardElevation * 1.5 + (1 - cos45) * cornerRadius on top and bottom.
和:
Note that, if you specify exact dimensions for the CardView, because of the shadows, its content area will be different between platforms before L and after L. By using api version specific resource values, you can avoid these changes. Alternatively, If you want CardView to add inner padding on platforms L and after as well, you can set setUseCompatPadding(boolean) to true.
如那里所述-您应该只使用 setUseCompatPadding (true)
然后在两者上使用外部填充:L 和 pre-L 将一样。