Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit f50474e

Browse files
committed
Fix the ClassCastException in DemoActivity
The R.id.motionlayout could be other Views (such as DrawerLayout in motion_13_drawerlayout.xml)
1 parent 8f0ff34 commit f50474e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample

motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/DemoActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,25 @@ import android.widget.ImageView
2626

2727
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) // for View#clipToOutline
2828
class DemoActivity : AppCompatActivity() {
29-
private lateinit var motionLayout : MotionLayout
29+
private lateinit var container: View
3030

3131
override fun onCreate(savedInstanceState: Bundle?) {
3232
super.onCreate(savedInstanceState)
3333
val layout = intent.getIntExtra("layout_file_id", R.layout.motion_01_basic)
3434
setContentView(layout)
35-
motionLayout = findViewById(R.id.motionLayout)
35+
container = findViewById(R.id.motionLayout)
3636

3737
if (layout == R.layout.motion_11_coordinatorlayout) {
3838
val icon = findViewById<ImageView>(R.id.icon)
3939
icon?.clipToOutline = true
4040
}
4141

4242
val doShowPaths = intent.getBooleanExtra("showPaths", false)
43-
motionLayout.setShowPaths(doShowPaths)
43+
(container as? MotionLayout)?.setShowPaths(doShowPaths)
4444
}
4545

4646
fun changeState(v: View?) {
47+
val motionLayout = container as? MotionLayout ?: return
4748
if (motionLayout.progress > 0.5f) {
4849
motionLayout.transitionToStart()
4950
} else {

0 commit comments

Comments
 (0)