【发布时间】:2011-07-25 19:07:33
【问题描述】:
我有一个自定义视图,我将它放在 ScrollView 中,如下所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.test.view android:id="@+id/myview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
我已经在我的自定义视图中实现了 onDraw() 和许多其他方法,还有 onMeasure:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(600, MeasureSpec.EXACTLY));
width = MeasureSpec.getSize(widthMeasureSpec);
height = MeasureSpec.getSize(heightMeasureSpec);
}
然后当我启动应用程序时,我从 onDraw() 方法获得了许多日志,并且 TouchEvent 得到了很好的处理,但我没有看到我的自定义视图。好像就在那里,但又好像看不见似的……
也许我错过了什么......?
谢谢
更新
Custom View 没什么特别的,只是一个显示 Bitmap 的 View:
private class myView extends View{
public myView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.packagebm);
canvas.drawBitmap(bm, 0, 0, null);
Log.i("myview", "onDraw()");
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY));
}
}
【问题讨论】:
-
它应该是什么样子?也许从您的角度发布完整的代码
-
去掉滚动视图会有影响吗?
-
<_ scrollview>
-
我的意思是显示有什么不同吗?
标签: java android layout graphics scrollview