我在我的应用程序中实现了CardView,一切正常,但如果我将半径放入卡片,图像周围会有一点填充.
它看起来像这样:

但是在android文档和本文中,图像采用了整个cardview,所以你可以帮助我实现这一目标.
我的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardCornerRadius="4dp">
<ImageView
android:id="@+id/media_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:alpha="0.8"
android:background="?attr/colorPrimary"
android:padding="4dp">
<TextView
android:id="@+id/media_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="11sp"/>
<TextView
android:id="@+id/category_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/primary_text"
android:textSize="12sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
注意:屏幕截图是在棒棒糖前设备上捕获的.
android android-layout android-cardview android-5.0-lollipop
我正在使用cardview作为我正在编写的自定义视图的根.我使用的是v7支持库.我的XML看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="6dp"
card_view:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- some other views -->
</LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
我的问题是我的卡片视图周围有一个白色边框.它看起来像是指示高度,因为它在右侧较厚.我试过调整,cardElevation并MaxCardElevation在我的XML中这样:
card_view:cardElevation="0dp"
并在我的自定义视图中的代码中扩展CardView并使用此布局:
setCardElevation(0);
setMaxCardElevation(0);
Run Code Online (Sandbox Code Playgroud)
但白色边界仍然存在.我不知道如何摆脱它.如果有人对此为何发生任何意见或建议如何删除白色边框,我们将不胜感激.非常感谢.
我不知道我应该在哪里解决这个问题,如果这是我的错,那么Picasso Lib Wrong或Cardview Library中就会有一些东西.
基本上我有一个CardView图像(全卡覆盖)和A TextView覆盖.
在Android 5.0设备上运行代码时,一切正常,Image获取其圆角.
但是,如果我在5.0之前的设备上运行它,图像重叠Cardlayout并且没有圆角.
你可以看看这个图片的比较:

以下是一些代码片段:
layout_row.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/pandaImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/pandaName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/pandaImage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@color/photo_tint"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="24sp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
加载图像的Recycler Adapter:
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
Photo p = photos.get(i);
Picasso.with(mContext).load(p.getUrl()).fit().into(viewHolder.mImage);
viewHolder.mPandaName.setText(p.getTitle());
}
Run Code Online (Sandbox Code Playgroud)