We very deliberately coalesce multiple invalidates into a single draw for
performance reasons (so we can perform a draw of the hierarchy once instead
of twice).  This also avoids showing the UI in partial states, where one
part of the window has been updated to a new state but another part hasn't.
You probably shouldn't be working around this.

On Mon, Apr 13, 2009 at 11:30 AM, Leisuresuit Larry
<larrywan...@gmail.com>wrote:

>
> Thanks for the explanation. We worked around this behavior send
> separate messages to a Handler on the UI thread. I'm curious, though,
> to why Android doesn't handle the invalidate regions separately.
>
> On Apr 9, 11:46 am, Romain Guy <romain...@google.com> wrote:
> > setText() invalidates the TextView entirely and when two invalidates
> > happen in the same UI event (as it is the case in your code), the
> > invalidate region becomes the union of the two original invalidate
> > regions.
> >
> >
> >
> > On Wed, Apr 8, 2009 at 6:40 PM, Leisuresuit Larry <larrywan...@gmail.com>
> wrote:
> >
> > > Hi all,
> >
> > > We came across a strange behavior. The cliprectof our custom view is
> > > getting reset to its entire visible region, if we change the value of
> > > another view.
> >
> > > Below is a sample app to demonstrate the behavior:
> >
> > > main.xml:
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> > > android"
> > >    android:orientation="vertical"
> > >    android:layout_width="fill_parent"
> > >    android:layout_height="fill_parent"
> > >    >
> >
> > > <com.test.MyView
> > >    android:id="@+id/view"
> > >    android:layout_width="fill_parent"
> > >    android:layout_height="100px" />
> >
> > > <TextView
> > >    android:id="@+id/text"
> > >    android:layout_width="fill_parent"
> > >    android:layout_height="wrap_content" />
> >
> > > </LinearLayout>
> >
> > > ClipTest.java:
> > > package com.test;
> >
> > > import android.app.Activity;
> > > import android.os.Bundle;
> > > import android.view.KeyEvent;
> > > import android.widget.TextView;
> >
> > > public class ClipTest extends Activity {
> > >    /** Called when the activity is first created. */
> > >    @Override
> > >    public void onCreate(Bundle savedInstanceState) {
> > >        super.onCreate(savedInstanceState);
> > >        setContentView(R.layout.main);
> > >    }
> >
> > >    @Override
> > >    public boolean onKeyDown(int keyCode, KeyEvent event) {
> > >        TextView tv = (TextView)findViewById(R.id.text);
> > >        tv.setText("Test");
> >
> > >        findViewById(R.id.view).invalidate(100, 0, 150, 75);
> > >        return true;
> > >    }
> > > }
> >
> > > MyView.java:
> > > package com.test;
> >
> > > import android.content.Context;
> > > import android.graphics.Canvas;
> > > import android.graphics.Rect;
> > > import android.util.AttributeSet;
> > > import android.view.View;
> >
> > > public class MyView extends View {
> >
> > >    public MyView(Context context) {
> > >        super(context);
> > >    }
> >
> > >    public MyView(Context context, AttributeSet attrs) {
> > >        super(context, attrs);
> > >    }
> >
> > >    protected void onDraw(Canvas canvas) {
> > >        super.onDraw(canvas);
> >
> > >        Rectclip= canvas.getClipBounds();
> > >        System.out.println("clip" +clip);
> > >    }
> > > }
> >
> > > If you run the above app, MyView.onDraw() prints "clipRect(0, 0, 320,
> > > 100)". If you comment out "tv.setText("Test");", then MyView.onDraw()
> > > prints "clipRect(100, 0, 150, 75)".
> >
> > > Why does setting the TextView's text affect MyView'scliprect? How
> > > can we get the correctcliprectin MyView.onDraw()? Thanks for any
> > > help!
> >
> > > Larry
> >
> > --
> > Romain Guy
> > Android framework engineer
> > romain...@android.com
> >
> > Note: please don't send private questions to me, as I don't have time
> > to provide private support.  All such questions should be posted on
> > public forums, where I and others can see and answer them
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to