0

I have a layout with the follwoing:

Framelayout with two ImageViews. Each ImageView has one image.

What I am trying to acheive is: on touch on the ImageView, the touch area should become transparent and show the image below.

Layout XML:

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

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/rect" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/i2" />
    </FrameLayout>

</LinearLayout>

So basically on touch on imageView2 the touch area should show the image from imageView1.

I just need some pointers or references.

mata
  • 361
  • 3
  • 14
user2229100
  • 191
  • 2
  • 13
  • I think you will have to manually change alpha levels on image, based on touch location. – mata Aug 13 '14 at 10:24
  • @mata any reference examples ? – user2229100 Aug 13 '14 at 12:46
  • 1
    Check this answer: http://stackoverflow.com/questions/5368774/make-certain-area-of-bitmap-transparent-on-touch – mata Aug 13 '14 at 12:49
  • @mata i did its a excellent solution but in that example the answer is drawing images dyanmically using onDraw, whereas i have a xml layout with imageviews in which i want to apply the effect – user2229100 Aug 13 '14 at 12:56
  • solved it , just learnt about custom views , implemented the code in the link @mata posted in a custom view and then used that custom view in my layout , cheers – user2229100 Aug 14 '14 at 03:34

2 Answers2

0

use this code inside your TouchListener

ImageView view1 = (ImageView)findViewById(R.id.imageView1);
view1.setZOrderOnTop(true);    // necessary
SurfaceHolder sfhTrackHolder = view1.getHolder();
sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);
Laxmeena
  • 780
  • 2
  • 7
  • 28
0

First get your local var fo the img

ImageView myImage2 = (ImageView) findViewById(R.id.imageview2);

Make sure you have a onClickListener on the myImage2, then:

 @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.imageview2) {
          myImage2.setAlpha((float) 0.55); //value: [0-1]. Where 0 is fully transparent .and 1 is fully opaque
    }
Joaquim Ley
  • 4,038
  • 2
  • 24
  • 42