Search code examples
androidxmlandroid-linearlayoutglsurfaceview

How put in LinearLayout class which extends GLSurfaceView?


my question is simple. I have class TouchSurfaceView which extends GLSurfaceView. I want create activity where will three TextViews and Button on bottom and TouchSurfaceView on top, but I don't know how read this in XML layout.


Solution

  • You just reference it usingthe full name (including the package) as if it were any other Vew:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <your.package.TouchSurfaceView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
         <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text"
            />
    <!-- etcetera -->
    </LinearLayout>
    

    You need a constructor that takes AttributeSet as parameter (is used when inflating the xml):

    public TouchSurfaceView(Context context, AttributeSet attr) {
      super(context, attr);
      // the rest of your code
    }