使用 WindowManager.addView 添加动态视图 [英] adding dynamic view using WindowManager.addView
问题描述
我有一个关于平板电脑 ICS 的代码.我想动态地将 Imageview 添加到片段中.该片段已包含首选项列表.动态添加视图的代码如下.我正在编写此拖放功能.这部分代码取自Android音乐应用程序的TouchInterceptor.java文件.
I have a code on ICS for tablets. I want to add a Imageview dynamicly to a fragment. The fragment already contains preferencelist. The code for adding the view dynamically is as follows. I am coding this drag and drop functionality. This part of the code is taken from TouchInterceptor.java file from android music app.
mWindowParams = new WindowManager.LayoutParams();
mWindowParams.gravity = Gravity.TOP ;
mWindowParams.x = 0;
mWindowParams.y = y
mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
mWindowParams.format = PixelFormat.TRANSLUCENT;
mWindowParams.windowAnimations = 0;
ImageView v = new ImageView(mContext);
int backGroundColor = mContext.getResources().getColor(R.color.bg_background);
v.setBackgroundColor(backGroundColor);
v.setImageBitmap(bm);
mWindowManager = (WindowManager)mContext.getSystemService("window");
mWindowManager.addView(v, mWindowParams);
我将 windowlayout 参数的 x 坐标指定为 0.事件然后当显示视图时,它不是从片段的左侧(右窗格)显示,而是从右窗格的中间显示并跨越到右侧窗格.我做错了什么?必须采取什么措施来纠正这个问题?
I am specifying the x coordinate of windowlayout param as 0. Eventthen when the view is displayed , itstead of displaying from the leftside of the fragment(the right pane) ,the view is displayed from middle of the right pane and is spanning to the right pane . What I am doing wrong ? Whats has to be done to correct this ?
推荐答案
尝试将重力设置为 Gravity.TOP |Gravity.LEFT
这篇关于使用 WindowManager.addView 添加动态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!