caj*_*iko 79 android android-cardview
我尝试使用它CardView并且它在5.0以下工作得很好,但在棒棒糖上看起来很奇怪.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<android.support.v7.widget.CardView android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="card1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView android:layout_width="match_parent"
android:layout_height="200dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="card2"
android:textAppearance="?android:attr/textAppearanceLarge" />
</android.support.v7.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我在使用时会遇到同样的问题RecyclerView,如果它在Lollipop上运行,我是否需要添加一些东西?
tom*_*ozb 204
设置为CardView:
app:cardUseCompatPadding="true"
Run Code Online (Sandbox Code Playgroud)
来自文档:
在API v21 +中添加填充以与先前版本具有相同的度量.
Oma*_*nik 29
在cardview内使用以下两个标签:
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
Run Code Online (Sandbox Code Playgroud)
nul*_*ter 12
第一张图片是卡片视图的预期行为.当卡片有高度时,阴影落在底层.在前棒棒糖装置中,通过添加填充来进行提升.所以前棒棒糖设备将在卡片视图周围有一个填充物.
在L之前,CardView会在其内容中添加填充并为该区域绘制阴影.此填充量等于两侧的maxCardElevation +(1 - cos45)*cornerRadius,顶部和底部的maxCardElevation*1.5 +(1 - cos45)*cornerRadius.
你必须添加app:cardUseCompatPadding="true"到你的Cardview.但只是添加它可能会给你一个错误.为避免该错误,您还必须添加xmlns:app="http://schemas.android.com/apk/res-auto"到您的CardView.
例如,
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:cardUseCompatPadding="true">
// Other views here
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
有些人会添加card_view:cardUseCompatPadding="true"而xmlns:card_view="http://schemas.android.com/apk/res-auto"不是上面提到的那些.两种方式都是正确的.
如果您想了解有关XML(Android)应用的更多信息,请通过以下答案:
虽然以前的答案将解决问题,但他们没有解释每个属性的作用.所以更有帮助回答寻求者,
cardPreventCornerOverlap 属性在v20和之前为CardView添加填充以防止卡内容和圆角之间的交叉.
cardUseCompatPadding 属性在API v21 +中添加填充以及与先前版本具有相同的度量.
| 归档时间: |
|
| 查看次数: |
40746 次 |
| 最近记录: |