Reputation: 13582
In the following snippet the onDraw
method is called around 10-15 times. Can anyone explain this behaviour
LinearLayout ll = new LinearLayout(this);
View v = new View(this) {
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
System.out.println("large view on draw called");
super.onDraw(canvas);
}
};
v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 2000));
LinearLayout ll2 = new LinearLayout(this);
ll2.addView(v);
ScrollView sv = new ScrollView(this);
sv.addView(ll2);
ll.addView(sv);
LinearLayout ll1 = new LinearLayout(this);
ll1.addView(ll);
Upvotes: 2
Views: 3610
Reputation: 1006604
Every time you do something that might affect a widget, the widget will be redrawn. Putting the widget in a container might affect it. Putting the container in another container might affect it.
You should be making no assumptions about how many times onDraw()
will be called, other than that it will be called a lot and therefore needs to be fast.
Upvotes: 3