android - ImageView 源总是覆盖它的背景 Android

标签 android xml

我想将一侧设置为 ImageView

like this

因此,我将其添加为 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"/>

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

谁能帮我找出解决办法?

最佳答案

找到了解决方案。这非常适合我。

在您的项目级 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

关于android - ImageView 源总是覆盖它的背景 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54006124/

相关文章:

java - 通过执行一个简单的 Spring Hibernate 集成程序,我遇到了以下问题

html - 如何为动态数据表创建xpath?

c# - 在c#中将特殊字符写入xml

android - YouTube 嵌入视频无法播放

android - android 数据库的大小会影响设备的电池效率吗?

java - 对 CONTENT_FILTER_URI 结果进行排序

java - 是否可以将 @XmlHeader 与 Jackson 一起使用?

java - 使用 < 和 > 解析 xml 文件

java - 异步任务中的空指针异常

java - Android ViewPager 删除当前页面并移至下一页