2012년 6월 30일 토요일

overlay를 만들기


overlay를 만들기
(popup , dialog, something like that...)

Several core classes (including Dialog, PopupWindow and some Menu implementations) create an “overlay layer” that exists above, and separate from, existing UI elements – this is why we don't need to use special layoutmanagers on underlying Activity contentViews in order to position them. While the documentation is sparse, and cloning those classes is challenging (due to the inaccessible com.android.internal classes like PolicyManager), it's actually fairly simple to implement the functionality.
Use WindowManager.addView(view, windowManagerLayoutParams) to add a new layer. Eg, to add a view glued to the bottom of the screen, that'll overlay existing content:
1
2
3
4
5
6
7
8
9
WindowManager.LayoutParams wlp = new WindowManager.LayoutParams();
wlp.gravity = Gravity.BOTTOM;
wlp.height = WindowManager.LayoutParams.WRAP_CONTENT;
wlp.width = WindowManager.LayoutParams.FILL_PARENT;
wlp.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
wlp.format = PixelFormat.RGBA_8888;
 
WindowManager wm = (WindowManager) getSystemService("window");
wm.addView(someView, wlp);
You can supply animation resources to the WindowManager.LayoutParams instance, but AFAICT there is no way to add or use programmatic animation to either the window or any of it’s content children.








Toast와 같이 최상위에 뷰 띄우기.

Toast도 일반적인 뷰처럼 구성하고, 윈도우에 add 하는 구조로 작성되어 있다.
간단히 Toast와 같이 최상위에 뷰를 띄우는 요소들에 대해 정리.

1. 레이아웃 구성
Toast는 makeText라는 static 메쏘드를 제공하는데, 간단히 토스트를 띄울 수 있도록한 메쏘드다.
요녀석을 살펴보면, 흔히 사용되는 루틴으로 이루어져 있다.
.
.
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View v = inflate.inflate( com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById( com.android.internal.R.id.message);
tv.setText( text );
.
.
2. 윈도우 레이아웃 설정
WindowManager.LayoutParams mParams = new WindowManager.LayoutParams();
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.windowAnimations = com.android.internal.R.style.Animation_Toast;
params.type = WindowManager.LayoutParams.TYPE_TOAST;
params.setTitle("Toast");

params.x = x위치
params.y = y위치
params.gravity = 정렬
params.verticalMargin
params.horizontalMargin

3. 보이기
플랫폼에서는 아래와 같이 윈도우 매니저를 얻어온다.
WindowManager wm = WindowManagerImpl.getDefault();
sdk내에서는 아래와 같이 서비스로 얻어오면 된다.
WindowManager wm =
(WindowManager) context.getSystemService( Context.WINDOW_SERVICE );


wm.addView( v , params );

세부 내용은 없지만 대략의 구성은 큰 차이가 없다.
 위의 형태로 뷰를 구성하면, 토스트와 같이 최상위에 뷰를 표시하게 된다.

출처 : http://blog.daum.net/haha25/5388074

댓글 없음:

댓글 쓰기