2016年6月13日

Draw SurfaceView from layout xml

Draw SurfaceView from layout xml

Xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/textView_idd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <jacky.justin.superflashlight.GameViewA
            android:id="@+id/surfaceView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </FrameLayout>

</RelativeLayout>



MySurfaceView

public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback, OnTouchListener {
MainActivity mainActivity;
public GameViewA(Context context) {
super(context);

}
public GameViewA(Context context, AttributeSet attrs, int defStyle) {
   super(context, attrs, defStyle);
   // TODO Auto-generated constructor stub
}

public GameViewA(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}

}

沒有留言:

張貼留言