android 중급 22강 Drawable 및 Layout tacademy
original source : https://youtu.be/nMP6fDNtbfY
Drawable obj는 내부에 getIntrinsicHeight(), getIntrinsicWidth() 함수들을 구현해서 외부에서 이 함수를 호출했을때 Drawable이 실제 그려지는 부분의 크기를 되돌린다.
Drawable obj는 내부에 setLevel(), setState() 함수들을 구현해서 각 level, state에 맞게 drawable obj가 행동하도록 만든다.
Drawable.Callback interface는 invalidateDrawable(),scheduleDrawable(),unscheduleDrawable()들을 구현해야 한다. 참조) https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback
=========================================================
아래는 custom view내부에서 drawable을 사용하는 경우를 보여주고 있다
=========================================================
ref) https://stackoverflow.com/questions/13640541/view-ondrawcanvas-c-versus-drawcanvas-c-in-android
There is difference between them
The onDraw(Canvas c) is a override method and automatically called when the view is being rendered. Here you can do your additional drawing like make circles, lines or whatever you want.
The draw(Canvas c) is used to manually render this view (and all of its children) to the given canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw(android.graphics.Canvas) instead of overriding this method. If you do need to override this method, call the superclass version.
Or in simple words draw(Canvas c) is simply a function that is not automatically called when the view is rendered. User is needed to provide the canvas on which this view will rendered and user also have to do all the drawing on the canvas before calling this function.
Just if someone was still looking for answer like me and didn't find it.
The draw() method is called by the framework when the view need to be re-drawn and the draw() method then calls the onDraw() to draw the view's content.
void draw(Canvas canvas) { ..... do default stuff (background, layers) onDraw(canvas) ..... do other stuff ( scroll bars, fading edges, children) }
=========================================================
개발자가 새로운 Layout을 만들고 그 안에서 새로누 LayoutParams를 만들어 사용하는 경우 Layout class 안에 generatedLayouParams(), generateDefaultLayoutParams(), checkLayoutParams()를 구현해 주어야 한다.