我有一个针对平板电脑的ICS代码.我想动态地添加一个
Imageview到片段.该片段已经包含偏好列表.动态添加视图的代码如下.我正在编写这个拖放功能.这部分代码来自
Android音乐应用程序的TouchInterceptor.java文件.
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.事件当显示视图时,它从片段左侧显示(右窗格),视图从右窗格的中间显示,并且正在向右窗格.我做错了什么?需要做些什么来纠正这个问题?
解决方法
尝试将重力设置为Gravity.TOP | Gravity.LEFT