[英]How to make the hide and show animation of custom view
I wanna hide and show my view with animation. 我想隐藏并用动画显示我的观点。
First of all I tried to make it with changing view's visible (GONE, VISIBLE) (I use Transition API) but there were bugs with animation. 首先,我尝试通过更改视图的可见性(消失,可见)(我使用Transition API)来做到这一点,但是动画存在一些错误。
Then I tried to do it with scale animation but there was a bug with a hint in editText (child view). 然后,我尝试使用比例动画来执行此操作,但是在editText(子视图)中存在带提示的错误。
class SearchAdditionalView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
private val transitionSet: TransitionSet by lazy {
val transitionSet = TransitionSet()
with(transitionSet) {
addTransition(ChangeBounds())
interpolator = DecelerateInterpolator()
duration = 200
}
transitionSet
}
init {
inflate(context, R.layout.include_search_navbar_addition, this)
}
fun toggle() {
visibility = View.VISIBLE
TransitionManager.beginDelayedTransition(parent as ViewGroup, transitionSet)
}
}
Are there good practices for this animation and how can I integrate it? 该动画是否有良好的做法,我如何集成它?
TransitionManager.beginDelayedTransition()
should be called first before making any changes to the ViewGroup
. 在对
ViewGroup
进行任何更改之前,应首先调用TransitionManager.beginDelayedTransition()
。 Check out the training docs which should give you an idea. 查看培训文档 ,这应该可以给您一个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.