我想将一侧设置为 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"/>
我也尝试过在运行时添加图像后以编程方式设置背景,但没有成功。
谁能帮我找出解决办法?
最佳答案
找到了解决方案。这非常适合我。
在您的项目级 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。
关于android - ImageView 源总是覆盖它的背景 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54006124/