-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.kt
95 lines (77 loc) · 3.01 KB
/
MainActivity.kt
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.tazkiyatech.animation.experiments
import android.animation.LayoutTransition
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
class MainActivity : AppCompatActivity() {
private val rootView: ViewGroup
get() = findViewById(R.id.rootView)
private val textView2: View
get() = findViewById(R.id.textView2)
private val textView3: View
get() = findViewById(R.id.textView3)
private val hideTextView2AndThenShowTextView3Button: View
get() = findViewById(R.id.hideTextView2AndThenShowTextView3Button)
private val hideTextView3AndThenShowTextView2Button: View
get() = findViewById(R.id.hideTextView3AndThenShowTextView2Button)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
hideTextView2AndThenShowTextView3Button.setOnClickListener { hideTextView2AndThenShowTextView3() }
hideTextView3AndThenShowTextView2Button.setOnClickListener { hideTextView3AndThenShowTextView2() }
}
private fun hideTextView2AndThenShowTextView3() {
if (textView2.isVisible) {
hideViewAndThenShowAnother(textView2, textView3)
}
}
private fun hideTextView3AndThenShowTextView2() {
if (textView3.isVisible) {
hideViewAndThenShowAnother(textView3, textView2)
}
}
private fun hideViewAndThenShowAnother(viewToHide: View, viewToShow: View) {
val transitionListener2 = object : LayoutTransition.TransitionListener {
override fun startTransition(
transition: LayoutTransition,
container: ViewGroup,
view: View,
transitionType: Int
) {
//nothing do
}
override fun endTransition(
transition: LayoutTransition,
container: ViewGroup,
view: View,
transitionType: Int
) {
transition.removeTransitionListener(this)
}
}
val transitionListener1 = object : LayoutTransition.TransitionListener {
override fun startTransition(
transition: LayoutTransition,
container: ViewGroup,
view: View,
transitionType: Int
) {
//nothing do
}
override fun endTransition(
transition: LayoutTransition,
container: ViewGroup,
view: View,
transitionType: Int
) {
transition.removeTransitionListener(this)
transition.addTransitionListener(transitionListener2)
viewToShow.visibility = View.VISIBLE
}
}
rootView.layoutTransition.addTransitionListener(transitionListener1)
viewToHide.visibility = View.GONE
}
}