新手请教个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无法显示
解决方案 »
- android 端使用zxing 扫描sdcard中的二维码图片的方法是什么?
- 求高手们看下这个界面如何居中,代码全部放上来,恳求指导!!!
- android的3D切换画面实现的代码
- 安装android 报错
- android添加开机铃音的最终解决方案
- 如何跳转到保存联系人页面
- android引用外部lib问题
- 求一只需增删改查小app, 高分来人,(对您来说一杯茶的功夫·······)
- VSYNC 是在哪turn on的?
- 为什么在2.3中listview能显示,到4.0就不行了呢
- HttpResponse response = httpclient.execute(httppost)执行抛出异常?能帮忙看下吗?
- sdk安装问题?eclipse问题?
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);