1

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

Asif Sb
  • 785
  • 9
  • 38
  • Look here http://stackoverflow.com/questions/2739971/overlay-two-images-in-android-to-set-an-imageview – vinothp Jun 30 '15 at 08:46

1 Answers1

1

Something like below should be helpful.

<RelativeLayout
    android:id="@+id/rl_profile_pic_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp">

    <ImageView
        android:id="@+id/img_profile_pic_non_editable"
        android:layout_width="110dp"
        android:layout_height="120dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:adjustViewBounds="true"
        android:background="@drawable/your_actual image"
        android:scaleType="center" />

    <ImageView
        android:id="@+id/img_camera_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:src="@drawable/your_tick_icon"
        android:visibility="gone" />
</RelativeLayout>

Where the first image view is your actual image. And second image is the tick mark you are going to place above it. Add a clicklistener to make tick mark visible or invisible. This code is based on my requirement. Please modify other properties as required.

Try to use tick mark image as icon size like 36x36,48x48,72x72,96x96

Vilas
  • 1,695
  • 1
  • 13
  • 13