Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:36:49+00:00 2026-05-31T21:36:49+00:00

I am trying to make Custom RelativeLayout which can scale and scroll. Right now

  • 0

I am trying to make Custom RelativeLayout which can scale and scroll. Right now I have tried to achieve scale. Now I have made the custom Relative layout as parent layout of another relative layout which contains touchable Imageview as its child. Now when I zoom the parent custom relative layout child also gets zoom but the clickable area of the Imageview translates I dont know why ? When Imageview or layout are at normal position the clickable area is on the Imageview but as soon as the layout gets zoom the clickable area shifts ? I do not know why am I facing weird position displacement of clickable

here is the code

my custom relative layourt

public class scaleLayout extends RelativeLayout {

    private float mScaleFactor=1.0f;
      private long lastTouchTime = -1;

    public scaleLayout(Context context)
    {
        super(context);

    //  setWillNotDraw(false);

    }

    public scaleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        //setWillNotDraw(false);


        // TODO Auto-generated constructor stub
    }


/*  @Override 
    public boolean dispatchTouchEvent(MotionEvent event) { 
                return super.dispatchTouchEvent(event); 
       } */

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub

        return super.onTouchEvent(event);
    }


    @Override
      public boolean onInterceptTouchEvent(MotionEvent ev) {

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {

          long thisTime = System.currentTimeMillis();
          if (thisTime - lastTouchTime < 250) {

            // Double tap
              mScaleFactor=1.5f;
              invalidate();
            lastTouchTime = -1;

          } else {

            // Too slow :)
            /*  mScaleFactor=1.0f;
              invalidate();*/
            lastTouchTime = thisTime;
          }
        }

        return super.onInterceptTouchEvent(ev);
      }




    @Override
    protected void dispatchDraw(Canvas canvas) {
        // TODO Auto-generated method stub

            canvas.save(Canvas.MATRIX_SAVE_FLAG);
            canvas.scale(mScaleFactor, mScaleFactor);
            super.dispatchDraw(canvas);
            canvas.restore();


    }


    @Override
    public ViewParent invalidateChildInParent(int[] location, Rect dirty) {
        // TODO Auto-generated method stub
        return super.invalidateChildInParent(location, dirty);
    }

    protected void onLayout(boolean changed, int l, int t, int r, int b)
    {
        int count = getChildCount();
        for(int i=0;i<count;i++){
            View child = getChildAt(i); 
            if(child.getVisibility()!=GONE){
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)child.getLayoutParams();
                child.layout(
                    (int)(params.leftMargin * mScaleFactor), 
                    (int)(params.topMargin * mScaleFactor), 
                    (int)((params.leftMargin + child.getMeasuredWidth()) * mScaleFactor), 
                    (int)((params.topMargin + child.getMeasuredHeight()) * mScaleFactor) 
                    );
            }
        }
    }

here is the activity

public class LayoutZoomingActivity extends Activity implements OnTouchListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView img1 = (ImageView) findViewById(R.id.imageView1);
        img1.setOnTouchListener(this);
        ImageView img2 = (ImageView) findViewById(R.id.imageView2);
        img2.setOnTouchListener(this);

    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub

        ImageView iv= (ImageView) v;
        v.setVisibility(View.INVISIBLE);


        return false;
    }

this is xml

<com.layoutzooming.scaleLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

 <RelativeLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/gm01"
    >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="jhkibnkij"
        android:layout_centerInParent="true"
        android:textColor="#FFFFFF"
        android:textSize="25dp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="500dp"
        android:layout_marginTop="250dp"
        android:background="#000"
        android:src="@drawable/dih01" />

     <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="350dp"
        android:layout_marginTop="250dp"
        android:background="#000"
        android:src="@drawable/dih02" />

 </RelativeLayout>
</com.layoutzooming.scaleLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:36:51+00:00Added an answer on May 31, 2026 at 9:36 pm

    Some how I managed to fix this issue by adding the below code in LayoutZoomingActivity .

     public class LayoutZoomingActivity extends Activity implements OnTouchListener {
    
        ImageView img1;     ImageView img2;     /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            img1 = (ImageView) findViewById(R.id.imageView1);
            img1.setOnTouchListener(this);
            img2 = (ImageView) findViewById(R.id.imageView2);
            img2.setOnTouchListener(this);
    
        }
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            Log.d("b","b");
            if(isViewContains(img1, (int)event.getX(), (int)event.getY()))      {
                img1.setVisibility(View.GONE);      }
            if(isViewContains(img2, (int)event.getX(), (int)event.getY()))      {
                img2.setVisibility(View.GONE);      }
    
            return false;
        }
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            // TODO Auto-generated method stub
            Log.d("onTouchEvent c","c"+(int)event.getX()+","+(int)event.getY());
            if(isViewContains(img1, (int)event.getX(), (int)event.getY()))      {
                img1.setVisibility(View.GONE);
                img1.invalidate();      }
            if(isViewContains(img2, (int)(event.getX()/scaleLayout.mScaleFactor), (int)(event.getY()/scaleLayout.mScaleFactor)))        {
                img2.setVisibility(View.GONE);
                img2.invalidate();      }
            return super.onTouchEvent(event);
        }
        private boolean isViewContains(View view, int rx, int ry) {
            int[] l = new int[2];
            view.getLocationOnScreen(l);
            int x = l[0];
            int y = l[1];
            int w = view.getWidth();
            int h = view.getHeight();
            Log.d("isViewContains::"+x+"::"+y+"::"+w+"::"+h,rx+"::"+ry);
            if (rx < x || rx > x + w || ry < y || ry > y + h) {
                return false;
            }
            return true;
        } }
    

    Can you please try this and customize according to your requirement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a custom jQuery toggle function. Right now, I have 2
I'm trying to make a custom infowindow. Version = 2. I have added my
Im trying to make custom icons for my HTC EVO, which is running Cyanogen
I'm trying to make my custom filter work... I have the following code in
I'm trying to make scrollable RelativeLayout, that contains some custom Views. This is the
I'm trying to make a custom UITableViewCell as I need to have specific control
I'm trying to make a custom validator work on my app. I have already
I'm trying to make a custom fold which goes through my sequence, and takes
Im trying to make a custom view that will have a dynamic number of
I'm trying to make a custom control in Silverlight have the same functionality as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.