Remove drop shadow of an ImageView

In Android Studio I integrated an ImageView with an unwanted drop shadow, which I cant seem to get rid off. How do you make the picture blend in to the background? I tried setting the background of the button to transparent and android:shadowRadius="0" did not work.

我的ImageView

My .xml file

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/colorWhiteText"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.Guideline
        android:id="@+id/guideline16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.23" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:shadowRadius="0"
        app:layout_constraintBottom_toTopOf="@+id/guideline16"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/logo_174" />

</android.support.constraint.ConstraintLayout>

Change the android:background="@color/colorWhiteText" to android:background="#ffffffff" as the background is important here.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="#ffffffff"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

Maybe better form to set this in resvaluescolors.xml:

<color name="windowBackground">#FFFFFFFF</color>

and use:

android:background="@color/windowBackground"

Tests ok for me (no drop shadow) with dependencies:

implementation 'com.android.support.constraint:constraint-layout:1.0.2'

I just found my stupid solution to this question. Make sure the picture itself has no drop shadow, which somehow wasn't the case. I was sure I had the picture as I wanted it to have it but somehow in the process a drop shadow was created.


1: You can check to value it is set

  android:background="@color/colorWhiteText"

2: If your image is a PNG try using the below

 android:src="@drawable/logo_174"

3: If the image is a vector. SrcCompact is used for vector image support for devices less than API level 21

 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }  

Note:The code shared by you is not giving any drop shadow when I tried.

链接地址: http://www.djcxy.com/p/816.html

上一篇: Mixins作为Polymer 2.0中的实用程序库

下一篇: 删除ImageView的投影