【问题标题】:How to Scroll Down Linear Layout When linearLayout is visible on button click [kotlin]如何向下滚动线性布局当linearLayout在按钮上可见时单击[kotlin]
【发布时间】:2019-02-15 20:12:14
【问题描述】:

我在滚动视图中有一堆文本视图和编辑文本表单,并且在这个线性布局中有一个垂直的文本视图在同一个滚动视图内的表单下方有一个线性布局。当用户按下“添加更多信息”时,最初线性布局的可见性消失了,它就在这个线性布局的上方,按钮然后布局可见性是可见的。这按预期工作正常,但我想要的是当线性布局变得可见时,滚动视图应该向下滚动,以便用户可以看到扩展数据。我尝试了所有但没有什么可以帮助我。 请帮我解决这个问题。下面是 ShowHideLayout 方法。 需要帮助

fun showHideLayout() {
    if (linearLayoutAddMoreInfoExpand.visibility == GONE) {

        linearLayoutAddMoreInfoExpand.visibility = VISIBLE
        mTextViewAddMoreInfo.setText("Close Add More Info")
        scrollView.post(Runnable {
        scrollView.fullScroll(ScrollView.FOCUS_DOWN)
            //scrollView.scrollTo(0,scrollView.bottom)
        })

       // scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        scrollView.scrollTo(0,scrollView.bottom)
        //scrollView.smoothScrollBy(R.id.linearLayoutAddMoreInfoExpand,R.id.scrollBottom)

    } else if (linearLayoutAddMoreInfoExpand.visibility== VISIBLE) {

        linearLayoutAddMoreInfoExpand.visibility = GONE
        mTextViewAddMoreInfo.setText("+ Add More Info")
    }
}

【问题讨论】:

    标签: java android kotlin scrollview android-linearlayout


    【解决方案1】:

    您可以解决此问题,在 xml 文件中的 exapandLinearLayout 之前添加另一个滚动视图,并在单击按钮时调用此滚动视图,这样您的线性布局就会向下滚动。但这可能不是最佳实践。 您的代码将如下所示

    <Scrollview
         android:id = @+id/scrollViewLayout
           .....
           ....>
        <LinearLayout....>
    
    <--Remaining view-->
    
    </LinearLayout>
           </Scrollview>
    

    在 Java 中的 addmoreinfo 按钮上单击调用此滚动视图,如下所示:-

        fun showHideLayout() { 
    if(linearLayoutAddMoreInfoExpand.visibility == GONE){ 
    linearLayoutAddMoreInfoExpand.visibility = VISIBLE
    mTextViewAddMoreInfo.setText("Close Add More Info")
    scrollViewLayout.post(Runnable { scrollView.fullScroll(ScrollView.FOCUS_DOWN)  })
    

    【讨论】:

      猜你喜欢
      • 2013-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      相关资源
      最近更新 更多