首页 > 解决方案 > ImageView 源始终覆盖其背景 Android

问题描述

我想将一侧设置为 ImageView

像这样

所以,我已将此作为背景添加到 ImageView

one_rounded_side.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="200.0"
android:viewportHeight="100.0">
<path
    android:fillColor="#000"
    android:pathData="M200,0H0v4.5h0v75.8h0c17.8,10.2 56,17.2 100.5,17.2c44.5,0 81.6,-7 99.5,-17.2h0V4.5h0V0z" />

并在运行时将图像设置为 ImageView,但我设置的图像始终会覆盖此背景可绘制对象。所以它像普通矩形一样显示。

我已经像这样添加了 ImageView

<ImageView
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="@drawable/one_rounded_side"
    android:scaleType="centerCrop"/>

我也尝试在运行时添加图像后以编程方式设置背景,但它没有奏效。

谁能帮我找出解决方案?

标签: androidxml

解决方案


得到了解决方案。这对我来说很完美。

在您的项目级别 build.gradle 中包含以下代码

allprojects {
repositories {
    ...
    maven { url "https://jitpack.io" }
}

}

在应用级 build.gradle 中包含以下代码

implementation 'com.github.developer-shivam:Crescento:1.2.1'

将此包含在您的 xml 文件中

<developer.shivam.crescento.CrescentoContainer
    android:id="@+id/crescentoContainer"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:elevation="1dp"
    android:scaleType="centerCrop"
    attribute:curvature="50dp">

    <ImageView
        android:id="@+id/iv_news_details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"/>
</developer.shivam.crescento.CrescentoContainer>

并在运行时将图像设置为 ImageView。

参考:https ://github.com/developer-shivam/Crescento


推荐阅读