如何在Android中禁用卡片视图周围的阴影 [英] How to disable the shadow around card view in android

查看:101
本文介绍了如何在Android中禁用卡片视图周围的阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在开发演示应用程序,其中使用了支持库的卡片视图.默认情况下,它会在其周围添加阴影.我要删除此阴影&应该看起来很简单.

Hello I am am working on demo application in which i am using the card view of support library. By default it is adding shadow around it. I want to remove this shadow & should looks like simple.

我尝试了这个对我不起作用的事情.

I tried this that is not working for me.

CardView cardView = (CardView) v.findViewById(R.id.cardView);
cardView.setElevation(0);

完成这些操作后我会崩溃

After doing these I am getting crash

11-06 15:12:17.018: E/AndroidRuntime(24315): FATAL EXCEPTION: main
11-06 15:12:17.018: E/AndroidRuntime(24315): Process: com.xyz, PID: 24315
11-06 15:12:17.018: E/AndroidRuntime(24315): java.lang.NoSuchMethodError: android.support.v7.widget.CardView.setElevation
11-06 15:12:17.018: E/AndroidRuntime(24315):    at com.xyz.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:85)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at com.xyz.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:1)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:2915)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:2511)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)
11-06 15:12:17.018: E/AndroidRuntime(24315):    at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)

layout.xml

layout.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"
    xmlns:app="http://schemas.android.com/apk/res/com.xyz"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:orientation="horizontal" >

谢谢.

推荐答案

在XML中使用此属性

card_view:cardElevation="0dp"

,并记住在根目录布局中添加xmlns:card_view="http://schemas.android.com/tools".

and remember add xmlns:card_view="http://schemas.android.com/tools" in your root layout.

OR ,您可以调用cardView.setCardElevation(0)以编程方式禁用阴影.

OR you can call cardView.setCardElevation(0) to disable shadow programmatically.

cardView.setElevation()方法和CardView属性android:elevation将在Android 5.0之前的平台中引发java.lang.NoSuchMethodError

cardView.setElevation() method and CardView attribute android:elevation will throw java.lang.NoSuchMethodError in platform before Android 5.0

这篇关于如何在Android中禁用卡片视图周围的阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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