試試這個我不是擴展surfaceview。
public class Preview_can_work extends Activity {
private SurfaceView surface_view;
SurfaceHolder.Callback sh_ob = null;
SurfaceHolder surface_holder = null;
SurfaceHolder.Callback sh_callback = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
surface_view = new SurfaceView(getApplicationContext());
addContentView(surface_view, new LayoutParams(50, 50));
if (surface_holder == null) {
surface_holder = surface_view.getHolder();
}
sh_callback = my_callback(); // CREATING CALLBACK FOR YOUR SURFACE.
surface_holder.addCallback(sh_callback);
}
// THIS FUNCTION RETURNS CALLBACK OBJECT FOR SURFACEVIEW.
SurfaceHolder.Callback my_callback() {
SurfaceHolder.Callback ob1 = new SurfaceHolder.Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
};
return ob1;
}
}
現在您可以簡單地添加任何文本視圖或按鈕在您的佈局應該工作。
注意: - 我正在動態創建表面。在你的情況下,你可以做的是你可以在xml文件中創建所有的東西。而不是創建表面視圖創建視頻視圖。 SurfaceView surface_view =(SurfaceView)findViewById(R.id.video_view_id);
如果你是從你的佈局獲取id的視圖,那麼你必須從代碼中刪除一些行。它們是:
surface_view = new SurfaceView(getApplicationContext());
addContentView(surface_view, new LayoutParams(50, 50));
希望它會幫助你...