我创建了一个自定义视图com.mydomain.android.KTab,如下图所示,我在顶部有一个FrameLayout,在底部有一个自定义视图。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/radialback">
<FrameLayout
android:id="@+id/contentFrame"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="top"
android:background="#ffcccccc"/>
<view
class="com.mydomain.android.KTab"
android:id="@+id/kTab"
android:layout_width = "fill_parent"
android:layout_height = "80dip"/>
</LinearLayout>
我以编程方式将ScrollView添加到 FrameLayout,如下面的代码所示:
TextView tv = new TextView(this);
tv.setText("a long long string...");
ScrollView sv = new ScrollView(this);
sv.addView(tv);
FrameLayout fl = (FrameLayout)findViewById(R.id.contentFrame);
fl.addView(sv);
现在从表面上看效果很好,但是当我滚动contentFrame时,我的自定义视图(在本例中为KTab )的 onDraw() 方法会不断被调用,我不明白为什么我的自定义视图会受到滚动的影响,它是不必要。
任何人都可以提供线索吗?