简体   繁体   English

在另一个ImageView上加载一个ImageView

[英]Loading an ImageView on top of another ImageView

I have 92 images and I would like to have an indicator such as a check mark to indicate that an image is unlocked. 我有92张图像,我想有一个指示符,例如对勾标记,以指示图像已解锁。 I have the check mark in a .png file and what I tried at first was to just make a seperate copy of each image with the check mark put on top of the image in photoshop. 我在.png文件中有一个复选标记,而我最初尝试的是将每个图像单独制作一个副本,并在Photoshop中将复选标记放在图像的顶部。 However I know that there must be a simpler way of just adding the check mark file on top of the image that is already there instead of having a copy of the image with the check mark already on it. 但是我知道,必须有一种更简单的方法,即仅在已存在的图像顶部添加对勾标记文件,而不要在图像上复制带有对勾标记的图像。

I have a GridViewAdapter class responsible for loading the original images into a gridview: 我有一个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;
}

where url is a list that contains the references to each image to be loaded 其中url是一个列表,其中包含要加载的每个图像的引用

the mentioned SquaredImageView class is: 提到的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());
    }
} 

Any suggestions are appreciated 任何建议表示赞赏

I can think of a few ways to do this: 我可以想到几种方法:

  • Option 1: 选项1:

    Wrap the SquaredImageView in a Framelayout and place another SqauredImageView inside of it. 包裹SquaredImageViewFramelayout ,并把另一SqauredImageView它里面。 Set the check mark on the second image view. 在第二个图像视图上设置复选标记。

  • Option 2: 选项2:

    Wrap the SquaredImageView in a FrameLayout and set the checkmark image on the foreground property of the FrameLayout (using setForeground ). 包裹SquaredImageViewFrameLayout和上设置复选标记图像foreground的的属性FrameLayout (使用setForeground )。

  • Option 3: 选项3:

    Create a ForegroundSquaredImageView which supports overlaying an image (similar to the foreground property of FrameLayout ). 创建ForegroundSquaredImageView它支持重叠的图像(类似于foreground的属性FrameLayout )。

    The code for something like this can be found here: https://gist.github.com/JakeWharton/0a251d67649305d84e8a . 这样的代码可以在这里找到: https : //gist.github.com/JakeWharton/0a251d67649305d84e8a You'll need to change it to extend from your SquaredImageView . 您需要将其更改为从SquaredImageView扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM