HorizontalScrollView: auto-scroll to end when new Views are added?

后端 未结 9 1198
鱼传尺愫
鱼传尺愫 2020-11-28 06:37

I have a HorizontalScrollView containing a LinearLayout. On screen I have a Button that will add new Views to the LinearLayout at runtime, and I\'d like the scroll view to

9条回答
  •  佛祖请我去吃肉
    2020-11-28 07:09

    This is my way for 3 ImageViews in kotlin:

    var p1 = true; var p2 = false; var p3 = false
    val x = -55
    val handler = Handler()
    handler.postDelayed(object : Runnable {
        override fun run() {
    
            if (p1){
                mainView.picsScrollViewID.smoothScrollTo(mainView.bigPic1ID.x.toInt() + x, 0)
                p1 = false
                p2 = true
                p3 = false
            }
            else if(p2){
                mainView.picsScrollViewID.smoothScrollTo(mainView.bigPic2ID.x.toInt() + x, 0)
                p1 = false
                p2 = false
                p3 = true
            }
            else if(p3){
                mainView.picsScrollViewID.smoothScrollTo(mainView.bigPic3ID.x.toInt() + x, 0)
                p1 = true
                p2 = false
                p3 = false
            }
            handler.postDelayed(this, 2000)
        }
    }, 1400)
    

提交回复
热议问题