gpt4 book ai didi

java - 如何将小图标覆盖在 ImageView 上的另一张图像上

转载 作者:行者123 更新时间:2023-12-01 23:41:36 26 4
gpt4 key购买 nike

我有一个 gridView 布局来显示图像,我想在图像上放置一个小图标作为标记。

这是我的代码:

ImageView i;
if (convertView == null) {
i = new ImageView(mContext);
i.setLayoutParams(new GridView.LayoutParams(width, height));
i.setPadding(10, 10, 10, 10);
i.setScaleType(ImageView.ScaleType.CENTER_CROP);

} else {
i = (ImageView) convertView;
}

if(mImageSet == IMAGE_SET_ONE) {
boolean cek = true;
i.setImageBitmap(decodeSampledBitmapFromResource(mContext.getResources(),mThumbIds[position],width,width));

}

请帮忙..

最佳答案

ImageView 小部件具有用于设置背景和前景图像的内置功能。你可以看看它在xml中的样子,src和background字段可以使用ImageView上的setImageResource和setImageBackground方法来设置。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:background="@color/pink"
android:src="@drawable/facebook_icon" />

</RelativeLayout>

First example

唯一的问题是 src(覆盖)图像将与 ImageView 的高度或宽度匹配。

因此,为了解决这个问题,您将在相对中使用多个 ImageView ,并单独设置每个图像的背景或 src。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:background="@color/pink" />

<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:src="@drawable/facebook_icon" />

</RelativeLayout>

Second example

关于java - 如何将小图标覆盖在 ImageView 上的另一张图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17837118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com