サポート カードビューに contentPadding を追加したいと思います。このパディングは 4.4 デバイスでは正しく計算されますが、4.1.2 デバイスでは contentpadding が機能しません。
build.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 は正しく認識されています。
このスレッドでこの問題の回避策を見つけました: Android L でCardView ウィジェットのパディングを設定する方法
編集: 現在、Android 4.1.2 を実行している Sony XPERIA L デバイスのバグのみのようです。4.1.2 を実行している Galaxy Nexus でテストしましたが、この場合はすべて問題なく表示されます。