2
在下面的片段中onDraw
方法被調用大約10-15次。任何人都可以解釋這種行爲嗎?Android onDraw調用大量次
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);
其實如果我不按照上面的層次結構,那麼最終的視圖似乎並沒有提供一個可滾動的視圖。除了第一次渲染視圖之外,還會發生10-15次onDraw調用。有什麼辦法來優化上述佈局。 – pankajagarwal 2010-12-24 04:53:54