在CardView不必要的填充? [英] Unnecessary padding in CardView?

查看:234
本文介绍了在CardView不必要的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序实现CardView,一切工作正常,除了有图像周围一点点填充,如果我把半径卡。

I have implemented CardView in my app and everything works fine except there is a little padding around the image if I put radius to the card.

这似乎是这样的: screenshot_2014-12-27-20-31-55

It appears like this:

但在 Android的文档和的this 图像。本文以整个cardview,所以u能帮助我实现了。

But in android docs and in this article the image takes the entire cardview, so can u help me achieve that.

我的布局文件是这样的:

My layout file is like:

<?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>

注:该屏幕截图抓获了pre-棒棒糖设备上

推荐答案

我通过去了<一href="https://developer.android.com/reference/android/support/v7/widget/CardView.html#set$p$pventCornerOverlap(boolean)">developer文档一遍,发现:

I went through the developer docs again and found that:

在20 API之前,CardView不夹卡的边界为圆角。相反,它添加填充到内容,以便它不会与圆角重叠。

On API 20 and before, CardView does not clip the bounds of the Card for the rounded corners. Instead, it adds padding to content so that it won't overlap with the rounded corners.

因此​​,对于pre-棒棒糖设备我必须调用设置preventCornerOverlap(假); 的cardview

So for pre-lollipop devices I have to call setPreventCornerOverlap (false); on the cardview.

这篇关于在CardView不必要的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆