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 6844871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:25:51+00:00 2026-05-27T00:25:51+00:00

Here is a weird behavior that I don’t understand about custom views. I have

  • 0

Here is a weird behavior that I don’t understand about custom views. I have two views in a frame layout, one on top of the other. The views are simple and I’ve made them just for a short test

public class View1  extends View  {
....

    @Override
     public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN){
            this.updateDrawings();
        }
        return true;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (canvas != null) 
        {
            Log.i("Test", "Draw View1");
        }
    }

    public void updateDrawings() {
        try {
            this.invalidate();
        }
        finally {
        }
    }
}

and View2

public class View2  extends View  {
....

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (canvas != null) 
        {
            Log.i("Test", "Draw View2");
        }
    }

    public void updateDrawings() {
        try {
            this.invalidate();
        }
        finally {
        }
    }
}

Everything well packed on a FrameLayout

<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffff">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">

            <com.View2
                android:layout_centerInParent="true"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginBottom="5dip" />
        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">

            <com.View1
                android:layout_centerInParent="true"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginBottom="5dip" />
        </LinearLayout>
</FrameLayout>

My question is: why when onTouch executes from View1, both view’s onDraw() method executes ? Why not only View1’s ?

Later Edit View2 has a big image to draw, the image is rotated and scaled according to some saved preferences. Normally, when I start the Activity, the View2.onDraw() takes care of rotating, translating and scaling of the Bitmap and draw it on canvas. When the user touches View1 I want only View1.onDraw() to execute because there’s no point to redraw the same background image over and over again for each user interaction. How can I stop View2.onDraw() to execute ?

  • 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-27T00:25:52+00:00Added an answer on May 27, 2026 at 12:25 am

    I think this should answer your question:

    http://developer.android.com/reference/android/view/ViewParent.html#requestLayout()

    “Called when something has changed which has invalidated the layout of a child of this view parent. This will schedule a layout pass of the view tree.”

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

Sidebar

Related Questions

I`m really confused here about this weird behavior! The thing is, I have a
Weird to describe but here goes. I have a table with several rows. One
I ran into a weird problem today that I don't really fully understand. Hopefully
I have a list of links that are exhibiting some really weird behavior. The
I have a little / weird behaviour here and Im looking over internet and
I'm battling a really weird problem here. I have a Windows 2008 R2 server
There is a weird code here that I need to make work.. can you
IDE = VS7 or 2002 Hi all, I have a really weird problem here.
I have something weird going on here. I just finished a site for a
I have a weird issue. Here is the setup: I have a NSOperationQueue which

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.