具有非透明背景图像的 ImageView
ImageView with Non-Transparent Background Image
我知道类似的问题被问过很多次,但这次不同。我有一张背景图片,我应该将它用于 ImageViews。图片不是矩形不透明,可以查看here or see below
这是我试过的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999"
android:padding="10dp"
android:gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_background"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/random_pic"
android:scaleType="fitXY"/>
</FrameLayout>
</LinearLayout>
结果如下所示:
当我删除 ImageView 结果是这样的:
如您所见,ImageView 与背景的形状不同。我也尝试了几种不同的方法,比如
将背景直接放到 ImageView,或者
将 View 更改为 ImageView 并使用圆形图像作为背景或它的源图像
它们没有效果。我也试过改变顺序,我把View放在ImageView之后,但是由于圆角背景不透明,我看不到ImageView,我只看到白色背景图像。
不改变rounded_background.png文件本身是不可能实现的吧?因为我知道如果背景是透明的就可以了。
谢谢
编辑: 如果不更改图像,则无法实现此目的。如果有人想学习实现这一目标的唯一方法,he/she 应该看到已接受的答案。
这是您的问题解决方案。
让你的背景图片像这样透明。
将您的主图像设置为 FrameLayout 背景图像。
这个背景是ImageView背景图。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="@drawable/randominage">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_background"
android:scaleType="fitXY" />
</FrameLayout>
我知道类似的问题被问过很多次,但这次不同。我有一张背景图片,我应该将它用于 ImageViews。图片不是矩形不透明,可以查看here or see below
这是我试过的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999"
android:padding="10dp"
android:gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_background"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/random_pic"
android:scaleType="fitXY"/>
</FrameLayout>
</LinearLayout>
结果如下所示:
当我删除 ImageView 结果是这样的:
如您所见,ImageView 与背景的形状不同。我也尝试了几种不同的方法,比如
将背景直接放到 ImageView,或者
将 View 更改为 ImageView 并使用圆形图像作为背景或它的源图像
它们没有效果。我也试过改变顺序,我把View放在ImageView之后,但是由于圆角背景不透明,我看不到ImageView,我只看到白色背景图像。
不改变rounded_background.png文件本身是不可能实现的吧?因为我知道如果背景是透明的就可以了。
谢谢
编辑: 如果不更改图像,则无法实现此目的。如果有人想学习实现这一目标的唯一方法,he/she 应该看到已接受的答案。
这是您的问题解决方案。
让你的背景图片像这样透明。
将您的主图像设置为 FrameLayout 背景图像。
这个背景是ImageView背景图。
<FrameLayout android:layout_width="match_parent" android:layout_height="170dp" android:background="@drawable/randominage"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rounded_background" android:scaleType="fitXY" /> </FrameLayout>