80,351
社区成员
发帖
与我相关
我的任务
分享
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="47dp"
android:background="#fff"
android:layout_alignParentTop="true"
android:id="@+id/top"
><TextView
android:layout_width="fill_parent"
android:layout_height="47dp"
android:text="hello"/>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollview"
android:layout_below="@+id/top">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.example.com.qige.demo.MyView
android:layout_width="fill_parent"
android:layout_height="450dp"
android:id="@+id/surfaceview"
></com.example.com.qige.demo.MyView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/surfaceview"
android:background="#fff"
android:text="1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
//内部类
class MyView extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder holder;
public MyView(Context context) {
super(context);
holder = this.getHolder();// 获取holder
holder.addCallback(this);
// setFocusable(true);
}
public MyView(Context context,AttributeSet attrs)
{
super(context,attrs);
holder = this.getHolder();// 获取holder
holder.addCallback(this);
// setZOrderOnTop(true);
// holder.setFormat(PixelFormat.TRANSLUCENT);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
new Thread(new MyThread()).start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
// 内部类的内部类
class MyThread implements Runnable {
@Override
public void run() {
Canvas canvas = holder.lockCanvas(null);// 获取画布
Paint mPaint = new Paint();
mPaint.setColor(Color.BLUE);
canvas.drawRect(new RectF(0, 0, 540, 780), mPaint);
holder.unlockCanvasAndPost(canvas);// 解锁画布,提交画好的图像
}
}
}