취미 기록용 블로그

안드로이드에서 팝업뷰 사용하기

안드로이드 작업을 하다 보니 현재뷰에서 다른 뷰를 레이어 띄우듯이 하는 상황이 발생해서 처음에는 투명한 다른 액티비티를 띄웠다가 골치아픈 문제가 발생해서 다른 방법을 찾다가 팝업뷰 라는걸 알게되서 여기에 정리해둠.

import android.view.LayoutInflater;
import android.widget.PopupWindow;

public class MainActivity extends Activity {
	private PopupWindow popupWindow = null;
	private View mMainView = null;

	public void onCreate(Bundle savedInstanceState) {
		mMainView = getLayoutInflater().inflate(R.layout.activity_mjview, null);
		LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
		View popupView = layoutInflater.inflate(R.layout.maincontrol, null);
		popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		
		//showAsDropDown (View anchor) 좌표가 anchor를 기준으로 돌아간다.
		popupWindow.showAsDropDown(mMainView);
		
       	//popupWindow.update(View anchor, int xoff, int yoff, int width, int height);
		popupWindow.update(mMainView, 0, 0, 100, 200);
}

자세한건 도움말 참조.
참고 사이트: http://arabiannight.tistory.com/331


Comments

답글 남기기

이메일 주소는 공개되지 않습니다. (이름과 이메일은 안써도 됩니다)

이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.