android - How to add a surfaceview into a fragment? -


i have surface view , fragment, need display surface view in fragment. below surface view , fragment classes.

is approach i'm doing right, draw in fragment? or have other suggestion?

fragment class:

public class fragment1 extends fragment{ public static int width,height; @override public view oncreateview(layoutinflater inflater,viewgroup   container,bundle savedinstancestate){              return new gameview(getactivity()); } 

fragment xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/index" android:orientation="vertical" >   </linearlayout> 

gameview(surface view)

public class gameview extends surfaceview {  private bitmap bmp;  private surfaceholder holder;    public gameview(context context) {        super(context);        holder = getholder();        holder.addcallback(new surfaceholder.callback() {               @override               public void surfacedestroyed(surfaceholder holder) {               }                @override               public void surfacecreated(surfaceholder holder) {                      canvas c = holder.lockcanvas(null);                      ondraw(c);                      holder.unlockcanvasandpost(c);               }                 @override               public void surfacechanged(surfaceholder holder, int format,                             int width, int height) {               }        });        bmp = bitmapfactory.decoderesource(getresources(),                    r.drawable.rec01);  }   @override  protected void ondraw(canvas canvas) {        canvas.drawcolor(color.black);        canvas.drawbitmap(bmp, 10, 10, null);  } 

}


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -