繁体   English   中英

删除ImageView的阴影

[英]Remove drop shadow of an ImageView

在Android Studio中,我集成了一个带有不需要的阴影的ImageView,我似乎无法摆脱它。 如何让图片融入背景? 我尝试将按钮的背景设置为透明和android:shadowRadius="0"不起作用。

我的ImageView

我的.xml文件

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

我刚刚找到了这个问题的愚蠢解决方案。 确保图片本身没有阴影,但事实并非如此。 我确信我有照片,因为我希望它有它,但不知何故在这个过程中创建了一个阴影。

android:background="@color/colorWhiteText"更改为android:background="#ffffffff"因为背景在这里很重要。

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

也许更好的形式在res \\ values \\ colors.xml中设置它:

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

并使用:

android:background="@color/windowBackground"

测试OK,我(没有阴影)与依赖关系:

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

1:您可以检查它已设置的值

  android:background="@color/colorWhiteText"

2:如果您的图片是PNG,请尝试使用以下内容

 android:src="@drawable/logo_174"

3:如果图像是矢量。 SrcCompact用于低于API级别21的设备的矢量图像支持

 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }  

注意:当我尝试时,您共享的代码没有给出任何阴影。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM