- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想在我的支持卡片 View 中添加一个 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 被正确识别。
我在这个线程上找到了解决这个问题的方法:How to set the padding for CardView widget in Android L但我想知道,是否有人面临这个问题或可以提供更好的解决方案?
编辑:目前这似乎只是运行 Android 4.1.2 的 Sony XPERIA L 设备上的一个错误。我使用运行 4.1.2 的 Galaxy Nexus 进行了测试,在这种情况下一切看起来都不错。
最佳答案
使用setUseCompatPadding(true)
,或者XML参数app:cardUseCompatPadding="true"
关于Android 支持 Cardview contentPadding 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27440362/
我想在我的支持卡片 View 中添加一个 contentPadding。此填充在 4.4 设备上计算正确,但在 4.1.2 设备上 contentpadding 不起作用。 build.gradle:
InputDecoration 带有预定的 contentPadding,如果我只想将 InputDecoration 的内容向左移动一点,我将不得不覆盖内部 contentPadding。 有没有办
我是一名优秀的程序员,十分优秀!