How to add a transparent image on the top of the image view when it is selected?

I have a set of image views in a row,when the user clicks on the image, the background is getting changed.I want to add a transparent image on the top of my image view with a small tick in the middle to indicate that it is selected.

final ImageView iv_image=new ImageView(this);
    LayoutParams iv_image_params=new LayoutParams(
            Math.round(100*multiplier),
            Math.round(100*multiplier));
    iv_image_params.setMargins(5, 5, 10, 5);
    iv_image.setId(Integer.parseInt(id));

    try {
        Bitmap bmp = BitmapFactory.decodeFile(DashBoard.file_path+image);
        iv_image.setImageBitmap(bmp);
        iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
        iv_image.setSelected(false);

    } catch (Exception e) {
    }
    iv_image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (iv_image.isSelected()==false) {
                iv_image.setBackground(getResources().getDrawable(R.drawable.border_only_image_based));
                iv_image.setSelected(true);

            } else {
                iv_image.setBackground(getResources().getDrawable(R.drawable.border_red_image_based));
                iv_image.setSelected(false);

            }

        }
    });

    ll_view.addView(iv_image, iv_image_params);

*border_only_image_based: is my selector where I am just setting white border for an image view to indicate that it is selected.

normal image:

enter image description here

the image I want to be on the top of that image view:

enter image description here


Source: android

Leave a Reply