Currently I have a custom SurfaceView for a specific size of Panels that I used for my project. But I'm looking into expanding it hence I need a ScrollView to scroll it accordingly. But I'm not sure how do I merge the 2 together.
My SurfaceView is using a .java file to create its layout. It is not using .xml to create the layout.
//MySurfaceView.class
public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback , Runnable{
private SurfaceHolder surfaceHolder;
private boolean isDestroyed = false;
private Canvas canvas;
private Paint paint;
private int maxWidth;
private int maxHeight;
private Resources resources;
int offset;
final byte ON=1;
final byte OFF=0;
int[] ledPositionControl = new int[97];
int ledBmpSize;
int positionControlSize;
int maxControl=96;
int sizeControl=0;
int row;
int col;
public MySurfaceView(Context context) {
super(context);
resources = context.getResources();
init(); //load pictures
surfaceHolder = this.getHolder();
surfaceHolder.addCallback(this);
paint =new Paint();
}
This is the class that runs the SurfaceView.
//Class that runs the SurfaceView Layout
public class drawingMode extends Activity implements OnClickListener {
public static int screenWidth;
public static int screenHeight;
private SharedPreferences sPrefs;
final byte ON = 1;
final byte OFF = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(new MySurfaceView(this));
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
screenWidth = metric.widthPixels;
screenHeight = metric.heightPixels;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Now how do I merge this SurfaceView into a ScrollView Layout? I have a .xml file that has a ScrollView inside but I tried to put the SurfaceView via tag wise through .xml but it didn't worked. I also tried the .addView and it didn't work too gave me some errors.
//I put this in a the onCreate of a class.
myScrollView = new ScrollView(getApplicationContext());
myScrollView.addView(new MySurfaceView(this));
setContentView(R.layout.scrollsurfaceview);
No comments:
Post a Comment