新手请教个SurfaceView的显示问题:
我的动态库内有个SurfaceView需要加入主程序中显示,但我发现那个view无论如何也无法在主程序界面上显示出来,而同时加入的Button显示没有问题。
于是做了个测试,如下:
1。dialog.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="vertical"
android:id="@+id/dialog">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<SurfaceView
android:id="@+id/sView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>2。MainActivity的onCreate函数中加入以下代码:
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
camerawnd = layoutInflater.inflate(R.layout.dialog, (ViewGroup) findViewById(R.id.dialog));
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
params.topMargin = 120;
params.leftMargin = 10;
params.gravity = Gravity.TOP|Gravity.LEFT;
params.width = 400;
params.height = 300;3。用addContentView显示正常
代码:this.addContentView(camerawnd, params);
这种情况下文字和SurfaceView都能显示4。在dialog内显示:
new AlertDialog.Builder(this).
setTitle("CameraView").
setView(camerawnd).
setIcon(R.drawable.ic_launcher).
setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
create().show();这种情况下,SurfaceView无法显示,但文字hello_world有显示,且hello_world与按钮“确定”间有很大一片空间,应该是留给SurfaceView的,但它却没有显示,为什么?SurfaceView的显示有什么条件吗?分不多,望各位大侠不吝指教SurfaceView 显示问题SurfaceView无法显示
我的动态库内有个SurfaceView需要加入主程序中显示,但我发现那个view无论如何也无法在主程序界面上显示出来,而同时加入的Button显示没有问题。
于是做了个测试,如下:
1。dialog.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="vertical"
android:id="@+id/dialog">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<SurfaceView
android:id="@+id/sView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>2。MainActivity的onCreate函数中加入以下代码:
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
camerawnd = layoutInflater.inflate(R.layout.dialog, (ViewGroup) findViewById(R.id.dialog));
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
params.topMargin = 120;
params.leftMargin = 10;
params.gravity = Gravity.TOP|Gravity.LEFT;
params.width = 400;
params.height = 300;3。用addContentView显示正常
代码:this.addContentView(camerawnd, params);
这种情况下文字和SurfaceView都能显示4。在dialog内显示:
new AlertDialog.Builder(this).
setTitle("CameraView").
setView(camerawnd).
setIcon(R.drawable.ic_launcher).
setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
create().show();这种情况下,SurfaceView无法显示,但文字hello_world有显示,且hello_world与按钮“确定”间有很大一片空间,应该是留给SurfaceView的,但它却没有显示,为什么?SurfaceView的显示有什么条件吗?分不多,望各位大侠不吝指教SurfaceView 显示问题SurfaceView无法显示
WindowManager wm = (WindowManager) getSystemService( Context.WINDOW_SERVICE);
WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION + 5, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
wm.addView(camerawnd, wmParams);