Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

android - adding dynamic view using WindowManager.addView

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);

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try setting gravity to Gravity.TOP | Gravity.LEFT


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...