布局文件:
<?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())动态图像的时候静态的图像也会跟着更新,这是为什么啊?
<?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())动态图像的时候静态的图像也会跟着更新,这是为什么啊?
/**
* 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);
}
}
}
执行DynamicTrackView对象的invalidate()可以不?
http://source.android.com/source/downloading.html