浏览 6526 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-10-10
最后修改:2009-10-10
继承View,实现自己想要的组件,那么需要使用到setMeasuredDimension这个方法,这个方法决定了当前View的大小,请看代码: package cc.mdev.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.text.TextPaint; import android.util.AttributeSet; import android.util.Log; import android.view.View; public class MyScrollView extends View { public MyScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public MyScrollView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { TextPaint paint = new TextPaint(); paint.setAntiAlias(true); canvas.drawColor(Color.GRAY); for (int i = 10; i < 500; i++) { canvas.drawText("This is the scroll text.", 10, i, paint); i = i+15; } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { String tag="onMeasure"; Log.e(tag, "Scroll View on measure..."); setMeasuredDimension(200, 800); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { String tag = "onScrollChanged"; Log.e(tag, "Scroll...."); super.onScrollChanged(l, t, oldl, oldt); } }
<?xml version="1.0" encoding="utf-8"?> <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="#fff" > <Button android:text="Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <cc.mdev.test.MyScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"/> </ScrollView> </LinearLayout>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |