금요일, 8월 06, 2010

[Android] Resize SurfaceView

Android Resize SurfaceView

:: in Activity Java Source Code
// Get SurfaceView LayoutParams info
android.view.ViewGroup.LayoutParams lp = m_SurfaceView.getLayoutParams();

// Set to params
lp.width = 320;
lp.height = 240;

// Apply to new dimension
m_SurfaceView.setLayoutParams( lp );
// Set left, top margin
int l = (getWindowManager().getDefaultDisplay().getWidth() - lp.width) / 2;
int t = (getWindowManager().getDefaultDisplay().getHeight() - lp.height) / 2;
((android.widget.RelativeLayout.LayoutParams)m_SurfaceView.getLayoutParams()).setMargins( l, t, 0, 0 );


// Restore to Full size
/*
lp.width = getWindowManager().getDefaultDisplay().getWidth();
lp.height = getWindowManager().getDefaultDisplay().getHeight();
m_SurfaceView.setLayoutParams( lp );
((android.widget.RelativeLayout.LayoutParams)m_SurfaceView.getLayoutParams()).setMargins( 0, 0, 0, 0 );
*/

-----
Cheers,
June

댓글 없음:

댓글 쓰기