Android视图生命周期是否有图形表示(状态图)?

时间:2023-01-26 09:01:50

We all know about the Android Activity's life cycle and Fragment's life cycles. But is there anything equivalent for views ?

我们都知道Android活动的生命周期和Fragment的生命周期。但是对于视图,有什么是等价的吗?

This could help, for instance, building custom views or give an in-depth look at a very common and often hidden graphic operation on Android.

例如,这可以帮助构建自定义视图,或者深入了解Android上一个非常常见的、通常是隐藏的图形操作。

Thanks in advance !

提前谢谢!

2 个解决方案

#1


68  

It isn't an official document, but this recently came up on Google+. The comments also have a good discussion with some detailed explanation.

它不是一份官方文件,但最近在谷歌+上出现。这些评论也有一个很好的讨论和一些详细的解释。

#2


4  

Here I created custom view that extends View. Then wrote logs in each method. Here the order of called methods:
When run debugging
setOverScrollMode
setOverScrollMode
onFinishInflate
setLayoutParams
getLayoutDirection
requestLayout
hasFocus
hasTransientState
getVisibility
getLayoutDirection
getLayoutDirection
canResolveLayoutDirection
getLayoutDirection
canResolveTextDirection
isLayoutDirectionResolved
isLayoutDirectionResolved
getLayoutDirection
getLayoutDirection
isLayoutDirectionResolved
isTextDirectionResolved
isTextAlignmentResolved
getLayoutDirection
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
getVisibility
onAttachedToWindow
jumpDrawablesToCurrentState
getBackground
isFocused
isShown
onVisibilityAggregated
refreshDrawableState
drawableStateChanged
onCreateDrawableState
isFocused
hasWindowFocus
getVisibility
onMeasure
getSuggestedMinimumWidth
getSuggestedMinimumHeight
getVisibility
getVisibility
onMeasure
getSuggestedMinimumWidth
getSuggestedMinimumHeight
getVisibility
getVisibility
layout
isOpaque
onSizeChanged
getBackground
isOpaque
getMatrix
isOpaque
isHardwareAccelerated
getZ
getElevation
getTranslationZ
onLayout
getVisibility
getAnimation
getLayerType
getLayerType
computeScroll
draw
onDraw
dispatchDraw
onDrawForeground
hasOverlappingRendering
dispatchWindowFocusChanged
onWindowFocusChanged
refreshDrawableState
drawableStateChanged
onCreateDrawableState
isFocused
hasWindowFocus

这里我创建了扩展视图的自定义视图。然后在每个方法中写入日志。这里所称方法的顺序是:当运行调试时,setOverScrollMode setOverScrollMode onfinishinflationsetlayoutparams getLayoutDirection requestLayout布局有焦点,hatransientstate getVisibility getLayoutDirection, getLayoutDirection canresoltdirection canresoltdirection, canresolvetdirection,方向是,解决了的,,,,,,,,,,,,,,,,,,,,,,,,:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的

Opening activity with this view:
onScreenStateChanged
getLayoutDirection
getAnimation
getLayerType
getVisibility
getVisibility
getVisibility
layout
getVisibility
dispatchWindowFocusChanged
onWindowFocusChanged
refreshDrawableState
drawableStateChanged
onCreateDrawableState
isFocused
hasWindowFocus

用这个视图打开活动:onScreenStateChanged getLayoutDirection getAnimation getLayerType getVisibility getVisibility, getVisibility布局getVisibility, dispatchWindowFocusChanged refreshDrawableState drawableStateChanged onCreateDrawableState isFocused hasWindowFocus

#1


68  

It isn't an official document, but this recently came up on Google+. The comments also have a good discussion with some detailed explanation.

它不是一份官方文件,但最近在谷歌+上出现。这些评论也有一个很好的讨论和一些详细的解释。

#2


4  

Here I created custom view that extends View. Then wrote logs in each method. Here the order of called methods:
When run debugging
setOverScrollMode
setOverScrollMode
onFinishInflate
setLayoutParams
getLayoutDirection
requestLayout
hasFocus
hasTransientState
getVisibility
getLayoutDirection
getLayoutDirection
canResolveLayoutDirection
getLayoutDirection
canResolveTextDirection
isLayoutDirectionResolved
isLayoutDirectionResolved
getLayoutDirection
getLayoutDirection
isLayoutDirectionResolved
isTextDirectionResolved
isTextAlignmentResolved
getLayoutDirection
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
jumpDrawablesToCurrentState
getVisibility
onAttachedToWindow
jumpDrawablesToCurrentState
getBackground
isFocused
isShown
onVisibilityAggregated
refreshDrawableState
drawableStateChanged
onCreateDrawableState
isFocused
hasWindowFocus
getVisibility
onMeasure
getSuggestedMinimumWidth
getSuggestedMinimumHeight
getVisibility
getVisibility
onMeasure
getSuggestedMinimumWidth
getSuggestedMinimumHeight
getVisibility
getVisibility
layout
isOpaque
onSizeChanged
getBackground
isOpaque
getMatrix
isOpaque
isHardwareAccelerated
getZ
getElevation
getTranslationZ
onLayout
getVisibility
getAnimation
getLayerType
getLayerType
computeScroll
draw
onDraw
dispatchDraw
onDrawForeground
hasOverlappingRendering
dispatchWindowFocusChanged
onWindowFocusChanged
refreshDrawableState
drawableStateChanged
onCreateDrawableState
isFocused
hasWindowFocus

这里我创建了扩展视图的自定义视图。然后在每个方法中写入日志。这里所称方法的顺序是:当运行调试时,setOverScrollMode setOverScrollMode onfinishinflationsetlayoutparams getLayoutDirection requestLayout布局有焦点,hatransientstate getVisibility getLayoutDirection, getLayoutDirection canresoltdirection canresoltdirection, canresolvetdirection,方向是,解决了的,,,,,,,,,,,,,,,,,,,,,,,,:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的,不透明的

Opening activity with this view:
onScreenStateChanged
getLayoutDirection
getAnimation
getLayerType
getVisibility
getVisibility
getVisibility
layout
getVisibility
dispatchWindowFocusChanged
onWindowFocusChanged
refreshDrawableState
drawableStateChanged
onCreateDrawableState
isFocused
hasWindowFocus

用这个视图打开活动:onScreenStateChanged getLayoutDirection getAnimation getLayerType getVisibility getVisibility, getVisibility布局getVisibility, dispatchWindowFocusChanged refreshDrawableState drawableStateChanged onCreateDrawableState isFocused hasWindowFocus