I want to make the view move around the screen. Is that possible?
in other words, I want panning to be possible and I think that has something to do with the view.
How do you do Panning a video preview?
I want to make the view move around the screen. Is that possible?
in other words, I want panning to be possible and I think that has something to do with the view.
How do you do Panning a video preview?
If you want to move your view all over the screen, its possible. Presuming this is indeed your requirement, here's what you could do. Make the view a child of Relative Layout. Everytime you want to move the view, get the RelativeLayout.LayoutParams of the child view, change relevent margins and set this as the child view's LayoutParam.
If you are doing this to a SurfaceView (needed to play the video), you get surfaceChanged callback everytime you change the margin.
Here's a sample code of the tweak I did for API Demos' CameraPreview activity which does the same. The SurfaceView is moved from left to right. Hope this helps.
Regards, Anirudh.
public class CameraPreview extends Activity {
protected static final String TAG = "CameraPreview";
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
mPreview.setId(100);
RelativeLayout mainLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams mainLp = new RelativeLayout.LayoutParams(640, 480);
mainLp.leftMargin = 20;
mainLayout.addView(mPreview, mainLp);
Button btn = new Button(this);
btn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
RelativeLayout.LayoutParams nLp = (LayoutParams) mPreview.getLayoutParams();
nLp.leftMargin += 10;
Log.v(TAG,"nLp.leftMargin: " + nLp.leftMargin);
mPreview.setLayoutParams(nLp);
}
});
btn.setText("Click me!");
RelativeLayout.LayoutParams btnLp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
btnLp.addRule(RelativeLayout.BELOW, mPreview.getId());
mainLayout.addView(btn ,btnLp);
setContentView(mainLayout);
}
}