일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- notification
- sqlite
- CoordinatorLayout
- View
- onLayout
- Algorithm
- onMeasure
- hilt
- activity
- BOJ
- HTTP
- Behavior
- 백준
- DataBinding
- CustomView
- 코틀린
- LiveData
- 알고리즘
- Android
- 안드로이드
- Navigation
- ViewModel
- recyclerview
- room
- lifecycle
- kotlin
- 알림
- CollapsingToolbarLayout
- AppBarLayout
- Coroutine
- Today
- Total
목록onMeasure (6)
개발일지
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/A7GGz/btrgDT6we0E/pS9iYP7kyjQv74PaTLPbj0/img.png)
Activity와 Fragment가 생명주기를 갖는 것처럼 View도 생명주기를 갖는다. Constructor View(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) context : 현재 테마와 리소스를 접근할 수 있도록 도와준다. 도한 동적으로 생성할 때 가장 간단한 방법이다. attrs : XML로 View를 Inflate할 때 XML로 속성을 받아오는 인터페이스다. defStyleAttr : 테마에서 기본 스타일을 지정할 수 있고, 기본 스타일에서 Attr값을 찾아와서 적용한다. defStyleRes : defStyleAttr에서 값을 찾을 수 없는 경우 defStyleRes를 사..
View가 그려지는 순서는 measure -> layout -> draw 과정을 거친다. 또한 전위순회 방식(부모를 그리고 자식을 형제순으로) 으로 그린다. Measure measure(widthMeasureSpec: Int, heightMeasureSpec: Int) View의 크기를 측정하는 과정이다. final 함수이지만 내부적으로 onMeasure를 호출하고 onMeasure를 재정의하여 사용할 수 있다. 아직 ChildView는 measure된 상태가 아니기 때문에 width, measuredWidth 는 0이 반환될 수 있다. setMeasureDimension(measuredWidth: Int, measuredHeight: Int) View의 크기를 측정한다. onMeasure에서 필수적으로..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cC7IGd/btq3Kevn0tW/2GxSj5dYKkROtiUTQbMBK0/img.png)
CustomeViewGroup Android에서 기본으로 제공하는 ViewGroup(Layout) 대신 ViewGroup을 상속받아 UI를 구축할 수 있다. OverlapLayout 전체코드 class OverlapLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) : ViewGroup(context, attrs, defStyleAttr, defStyleRes) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { var width = 0 var height..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/zcQIC/btq3Odhciqq/17WKenB6s5mQkA0hPchkm1/img.png)
MeasureSpec MeasureSpec은 View의 크기를 정할 때 중요하게 쓰인다. MeasureSpec은 ParentView에서 ChildView로 전달되며 크기에 대한 정보와 MeasureSpec Mode에 대한 정보로 구성되어 있다. MeasureSpec Mode UNSPECIFIED : Mode가 설정되지 않은 경우며 원하는 크기를 가질 수 있다. EXACTLY : 정확한 사이즈가 정해진 상태며 정해진 사이즈 안에서 원하는 크기를 가질 수 있다. (match_parent, fill_parent, 500dp 등 정확한 사이즈가 정해진 경우에 할당된다.) AT_MOST : 주어진 사이즈에서 원하는 크기를 가질 수 있다. (wrap_content로 주어진 경우 할당된다.) MeasureSpec 사..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/4XB54/btq3KdWNNto/z2ac2etkDp8tOB10UQsya0/img.png)
CustomView Android에서 기본으로 제공하는 View로 UI를 구축할 수 없을 때 사용자가 직접 View를 상속받아서 CustomView를 만들 수 있다. ProgressView 전체코드 class ProgressView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) : View(context, attrs, defStyleAttr, defStyleRes) { private val progressBarBackgroundPaint = Paint().apply { isAntiAlias = true style = Paint.Style.ST..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/cI1D0A/btq3JeO4mSV/V8R7Hr5oZk5xBxu2Jso5A1/img.png)
Android는 View와 ViewGroup을 통해 UI를 구축하여 사용자와 상호작용할 수 있다. 기본적으로 Button, TextView 등의 View와 ConstraintLayout, LinearLayout 등의 ViewGroup을 제공하기 때문에 쉽게 앱을 제작할 수 있다. 하지만 기본적으로 제공하는 View와 ViewGroup으로 원하는 UI를 구축할 수 없는 경우가 있으며, 이런 경우 View와 ViewGroup을 상속받아 직접 구현할 수 있고 기존의 정의된 View를 상속받아 기능을 확장할 수 있다. View Method View에서 제공하는 Method를 재정의하면서 View를 Custom화 할 수 있다. 구분 함수 설명 생성 constructor(Context) 코드에서 View를 생성할 ..