외부 라이브러리를 사용하는 과정에서 화면에서 보일 TextView를 인자로 넘겨주는 경우가 생겼다.
설상가상으로 TextView 자체의 디자인도 복잡하고 margin 값 적용이 필요한 경우였는데, WindowManager.LayoutParams만 layoutparams로만 정의해야 하는 제약까지 있었다.
만약 LinearLayout이나 RelativeLayout으로도 layoutParams 정의가 가능하면 아래처럼 쉽게 끝낼 수 있다.
layoutParams = LinearLayout.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT
).apply {
setMargins(1,2,3,4)
}
layoutParams = RelativeLayout.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT
).apply {
setMargins(1,2,3,4)
}
하지만 WindowManager만 사용해야하고, 배경까지 있는 경우는 아래와 같이 적용하면 쉽게 해결할 수 있다.
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetRight="20dp" //margin
android:insetBottom="20dp"> //margin
<shape android:shape="rectangle">
<corners android:radius="24dp" />
<padding
android:bottom="5dp"
android:left="10dp"
android:right="10dp"
android:top="5dp" />
<solid android:color="@color/white" />
</shape>
</inset>
'Android' 카테고리의 다른 글
[Android] Android Architecture Components(AAC) (0) | 2022.04.27 |
---|---|
[Android] Retrofit2 (0) | 2022.04.07 |
[Android] 디바이스 화면 해상도 구하기 (0) | 2022.03.28 |
[Android] CameraX (0) | 2022.01.10 |
[Android] JitPack 안드로이드 라이브러리 모듈 배포하기 (0) | 2021.12.30 |