Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- android12
- Dynamic Programing
- DFS
- 티스토리챌린지
- 카카오로그인
- android #google console
- android #androidstudio #compose #kotlin
- 백준 5052
- algorithm
- android #android studio #compose #kotlin
- alogrithm
- androidstudio
- AlertDailog
- cs #computer #network #internet
- KioskMode
- 오블완
- algoritm
- 안드로이드#코틀린
- android #androidstudio #fragmentdialog #kotlin
- Jetpack Compose
- algorithm #
- kotlin
- Android
- BFS
- mutablestatelistof
- android #androidstudio #zsh
- compose
- Bluetooth Permission
- mutablestateof
- 안드로이드 앱 아키텍처
Archives
- Today
- Total
스태틱하게 개발중
[Android] FragmentDialog 동적으로 Size, 위치 조절하기 본문
다이얼로그를 구현하다보면 원하는 사이즈나 위치를 설정해줘야 할 때가 있습니다.
val params = dialog!!.window!!.attributes
val metrics = resources.displayMetrics
val widthPixels = metrics.widthPixels
val heightPixels = metrics.heightPixels
params?.width = (widthPixels * 0.7).toInt()
params?.height = (heightPixels * 0.2).toInt()
dialog!!.window!!.attributes = params
dialog!!.window!!.setGravity(Gravity.TOP or Gravity.END)
dipalyMetrics로 화면 사이즈를 구한다음 화면 비율에 맞게 계산해줍니다.
계산해준 값을 dialog attributes에 넣어주면 됩니다.
다이얼로그의 위치는 레이아웃의 gravity 옵션을 사용하면 됩니다.
오른쪽 위로 위치시켜야 한다면 Gravity.TOP or Gravity.END 으로 설정해줍니다.
위의 설정값은 화면 끝에 붙기 때문에 여백을 주고싶다면 xml에서 rootLayout의 padding 값을 주어 원하는 위치를 조절해주면 됩니다.
'Android' 카테고리의 다른 글
| [Android] zsh: command not found: adb 환경변수 설정 (0) | 2023.10.19 |
|---|---|
| [Android] 안드로이드12 새로운 Bluetooth 권한대응 (0) | 2023.09.08 |
| [Android] WebView 파일 다운로드 기능 (0) | 2023.08.23 |
| [Android] 안드로이드 프로젝트 카카오 로그인 적용해보기 (0) | 2022.06.29 |
| [Android] 카카오 로그인 SDK사용을 위해 설정하기 (0) | 2022.06.29 |