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 |
| 31 |
Tags
- ExifInterface
- webview
- App Startup
- jsontokotlinclass
- notification setting
- prettyJson
- Plugins
- notification
- 403 Error
- Android
- datastore
- 이미지 gps
- application
- LOG
- ChromeCustomTab
- navigation component
- skipcollapsed
- Git
- shotcut
- BottomSheetDialog
- Blinking
- notification bar
- requestPermission
- ActivityResultContracts
- onResume
- room
- onReceivedSslError
- kdoc-generator
- itemAnimator
- circlecrop
Archives
- Today
- Total
Debbi Story
DataBinding으로 layout_weight 값 적용하기 본문
728x90
안드로이드 LinearLayout 사용시 비율을 주고싶을때 사용하는 속성!
layout_weight이 있습니다.
타입은 float형으로 되어있는데요.
저는 DataBinding과 ViewModel을 사용해 값을 변경해주고 싶었지만 오류가 생깁니다!!
아래 처럼 BindingAdapter를 사용하면 됩니다!
object MainBindings {
@JvmStatic
@BindingAdapter("android:layout_weight")
fun setLayoutWeight(view: View, weight: Float) {
val layoutParams = view.layoutParams as? LinearLayout.LayoutParams
layoutParams?.let {
it.weight = weight
view.layoutParams = it
}
}
}
'안드로이드 > Tip' 카테고리의 다른 글
| Custom Notification bar 만들기 (0) | 2020.10.28 |
|---|---|
| Room Insert시 rowId 얻기 (0) | 2020.10.23 |
| BottomSheetDialogFragment background 설정하기 (0) | 2020.09.10 |
| ViewPager2의 notifyDataSetChanged() 안될 때 (0) | 2020.08.18 |
| ViewPager2 가 Fragment 안에 있을때 (0) | 2020.08.18 |