[英]Loading an ImageView on top of another ImageView
我有92张图像,我想有一个指示符,例如对勾标记,以指示图像已解锁。 我在.png文件中有一个复选标记,而我最初尝试的是将每个图像单独制作一个副本,并在Photoshop中将复选标记放在图像的顶部。 但是我知道,必须有一种更简单的方法,即仅在已存在的图像顶部添加对勾标记文件,而不要在图像上复制带有对勾标记的图像。
我有一个GridViewAdapter类,负责将原始图像加载到gridview中:
@Override public View getView(int position, View convertView, ViewGroup parent) {
SquaredImageView view = (SquaredImageView) convertView;
if (view == null) {
view = new SquaredImageView(context);
view.setScaleType(CENTER_CROP);
}
// Get the image URL for the current position.
Integer url = getItem(position);
// Trigger the download of the URL asynchronously into the image view.
Picasso.with(context) //
.load(url) //
//
.error(R.drawable.error) //
.fit() //
.into(view);
return view;
}
其中url是一个列表,其中包含要加载的每个图像的引用
提到的SquaredImageView类是:
/** An image view which always remains square with respect to its width. */
final class SquaredImageView extends ImageView {
public SquaredImageView(Context context) {
super(context);
}
public SquaredImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
}
}
任何建议表示赞赏
我可以想到几种方法:
选项1:
包裹SquaredImageView
在Framelayout
,并把另一SqauredImageView
它里面。 在第二个图像视图上设置复选标记。
选项2:
包裹SquaredImageView
在FrameLayout
和上设置复选标记图像foreground
的的属性FrameLayout
(使用setForeground
)。
选项3:
创建ForegroundSquaredImageView
它支持重叠的图像(类似于foreground
的属性FrameLayout
)。
这样的代码可以在这里找到: https : //gist.github.com/JakeWharton/0a251d67649305d84e8a 。 您需要将其更改为从SquaredImageView
扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.