我想在我的支持卡片视图中添加一个 contentPadding。此填充在 4.4 设备上正确计算,但在 4.1.2 设备上,内容填充不起作用。
构建.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
}
xml布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardCornerRadius="4dp"
card_view:contentPaddingLeft="32dp"
card_view:contentPaddingRight="32dp"
card_view:contentPaddingTop="32dp"
card_view:contentPaddingBottom="32dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a very long text with more blablablablablablablablabla bla bla bla blablablablabla bla blablablablablabla blablablablabla blablablablabla blablabla"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
运行4.1.2的设备上的结果:
无法识别 contentPadding。
运行4.4.2设备的相同应用程序:
contentPadding 被正确识别。
我在这个线程上找到了解决这个问题的方法:How to set the padding for CardView widget in Android L 但我想知道,如果其他人面临这个问题或者可以提供更好的解决方案?
编辑: 目前它似乎只是运行 Android 4.1.2 的索尼 XPERIA L 设备上的一个错误。我使用运行 4.1.2 的 Galaxy Nexus 进行了测试,在这种情况下,一切看起来都不错。