programmatically define a SurfaceView and use in a xml layou

how to manipulate view and surface in layouts
fabiodelorenzo
Posts: 65
Joined: Thu Oct 03, 2013 5:54 pm

programmatically define a SurfaceView and use in a xml layou

Postby fabiodelorenzo » Thu Oct 03, 2013 5:59 pm

The layout file: main.xml
package info.delorenzo.quindici


Code: Select all

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textTite"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:text="@string/app_name" />

     <!-- THIS IS IMPORTANT -->
     <info.delorenzo.quindici.Panel
        android:layout_width="fill_parent"
        android:layout_height="330dp"  />
     <!-- --------------------------- -->

    <TextView
        android:id="@+id/textTime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:text="TIME" />

</LinearLayout>



<info.delorenzo.quindici.Panel ... /> is the SurfaceView View in the layout between two TextView elements

The Panel class:
package info.delorenzo.quindici;


Code: Select all

import ...;

public class Panel extends SurfaceView implements SurfaceHolder.Callback {

    public Panel(Context context) {
       super(context);   
    }

   public Panel(Context context, AttributeSet attrs) {
      super(context, attrs);
   }

   public Panel(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
   }

   @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        drawGrid();
    }

 private void drawGrid()
    {
        canvas = this.holder.lockCanvas();
        canvas.drawRect(x1,y1,x2,y2, paint );
        this.holder.unlockCanvasAndPost(canvas);
    }
}

Return to “Surface, View and Layout”

Who is online

Users browsing this forum: No registered users and 2 guests