布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  
   
    <com.track.StaticTrackView 
    android:id="@+id/staticTrackView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true"/>
    
    <com.track.DynamicTrackView 
    android:id="@+id/dynamicTrackView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" />
    
</FrameLayout>FrameLayout中有两个自定义图形,一个是静态的图像,另一个是动态的图形; 顾名思义静态的图像是不需要时时更新的,而动态的图像随着时间的变化会有所变化, 现在的问题是我在更新(View.invalidate())动态图像的时候静态的图像也会跟着更新,这是为什么啊?

解决方案 »

  1.   

    由layout文件可知,这两个图形是上下覆盖的,下面的是静态的图形,上面的是动态的图像,而且上面图形的画布是透明的,所以看起来就像在静态图像的上面画一些动态的东东;当初之所以这样设计就是为了提高程序效率,减少不必要的重绘,谁知道还是避免不了静态图像的重绘!!!哪位高手知道怎么回事??
      

  2.   

    看源码ms父控件内的子控件 重绘后会强制重绘一次子控件所在矩形内所有的子控件p.invalidateChild(this, r); 
        /**
         * Invalidate the whole view. If the view is visible, {@link #onDraw} will
         * be called at some point in the future. This must be called from a
         * UI thread. To call from a non-UI thread, call {@link #postInvalidate()}.
         */
        public void invalidate() {
            if (ViewDebug.TRACE_HIERARCHY) {
                ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE);
            }        if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS)) {
                mPrivateFlags &= ~DRAWN & ~DRAWING_CACHE_VALID;
                final ViewParent p = mParent;
                final AttachInfo ai = mAttachInfo;
                if (p != null && ai != null) {
                    final Rect r = ai.mTmpInvalRect;
                    r.set(0, 0, mRight - mLeft, mBottom - mTop);
                    // Don't call invalidate -- we don't want to internally scroll
                    // our own bounds
                    p.invalidateChild(this, r);
                }
            }
        }
      

  3.   

    应该可以只更新DynamicTrackView的
    执行DynamicTrackView对象的invalidate()可以不?
      

  4.   

    你可以这样试试,如果你那个静态的只一张图片的话,你完全没必要。用一个View来显示。直接在xml中设置就行了。至于那个动态的,可以用View来显示。
      

  5.   

    两个控件是平行上面的控件大小改变或设置了透明度也会重绘的,源码下载文档上有具体说明
    http://source.android.com/source/downloading.html