可绘制为CardView的背景 [英] Drawable as Background for CardView

查看:83
本文介绍了可绘制为CardView的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我通过android:backround设置了可绘制背景,CardView(android.support.v7.cardview)仍然保持白色:该文档给我的感觉是它应该可以工作.不知道我在这里做什么错了.

the CardView ( android.support.v7.cardview ) stays white even though I set a backround drawable via android:backround - The documentation gives me the feeling that it should work. No Idea what I am doing wrong here.

推荐答案

我知道这是一个老问题,但是我有一个简单的解决方案-只需将您的 CardView 的第一个孩子设为ImageView,然后将比例类型指定为 fitXY .您可以通过将 cardElevation cardMaxElevation 设置为0dp来摆脱多余的CardView填充:

I know this is an old question, but I have a simple solution - just make the first child of your CardView an ImageView and specify the scale type to fitXY. You can get rid of the extra CardView padding by setting cardElevation and cardMaxElevation to 0dp:

<?xml version="1.0" encoding="utf-8"?>
<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_width="match_parent"
    android:layout_height="200dp"
    app:cardCornerRadius="4dp"
    app:cardElevation="0dp"
    app:cardMaxElevation="0dp">

    <ImageView
        android:src="@drawable/your_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"/>

    <... your layout

    .../>


</android.support.v7.widget.CardView>

这篇关于可绘制为CardView的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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