티스토리 뷰

반응형

fragment를 이용하여 Dialog를 만들었다. 

우선 xml 을 생성하고, 해당 xml에 layout_height와 layout_width를 정의하면서, wrap_content(height), match_parent(width) 로 설정하였다. 

그리고 activity에 fragment를 연결해주었다.

그 다음은 fragment 에서 LayoutInflater를 통해 container(부모뷰)에 등록해주었다. 

 

그러나... 

fragment의 크기가 xml에 설정된 사이즈대로 생성되지 않은 것!!!!!! (width가 match_parent로 설정되지 않음.)

그래서 열심히 구글링 !!! 

찾은 방법은 아래와 같다. 

 

나는 fragment를 dialog 처럼 사용할 것이므로, 기본 AlertDialog의 width 크기로 설정하고 싶었다. 

height는 나의 wrap_content로... width는 match_parent로 ...

 

방법

1. Fragment 의 onResume 메소드 내에서 

2. dialog의 window 속성을 변경하여 설정

 

코드

 

정상동작!!!! ㅎㅎ

 

참고

https://stackoverflow.com/questions/12478520/how-to-set-dialogfragments-width-and-height

 

How to set DialogFragment's width and height?

I specify the layout of my DialogFragment in an xml layout file (let's call it layout_mydialogfragment.xml), and its layout_width and layout_height attributes particularly (to be 100dp each let's s...

stackoverflow.com

 

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함