简体   繁体   English

如何向下滚动线性布局当按钮上显示linearLayout时,单击[kotlin]

[英]How to Scroll Down Linear Layout When linearLayout is visible on button click [kotlin]

I have bunch of text view and edit text form inside a scroll view and also having a linear Layout below form inside same scroll view in this linear layout having bunch of text view vertical. 我在滚动视图中有一堆文本视图和编辑文本表单,并且在具有一堆文本视图垂直的线性布局中,在同一滚动视图中的表单内部也有一个线性布局。 Initially linear layout has visibility gone when user press "add more info",which is aling just above this linear layout, button then layout visibility is Visible. 最初,当用户按下“添加更多信息”时,线性布局的可见性消失了,该状态正好在此线性布局上方,然后单击按钮即可看到可见的布局。 This is working fine as expected but what i want is when linear layout get visible then scroll view should scroll down so that user can see the extended data. 这按预期工作正常,但是我想要的是当线性布局变得可见时,滚动视图应向下滚动,以便用户可以看到扩展的数据。 I tried all but nothing can help me. 我尽了一切,但没有任何办法可以帮助我。 Please help me to solve this.Below is ShowHideLayout method. 请帮我解决这个问题。下面是ShowHideLayout方法。 Need Help 需要帮忙

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")
    }
}

You can solve this adding another scrollview before your exapandLinearLayout in xml file and call this scrollview on button click so your whenever your linear layout is it will scroll down. 您可以解决此问题,方法是在xml文件中的exapandLinearLayout之前添加另一个scrollview,并在按钮单击时调用此scrollview,这样您的线性布局就会向下滚动。 But it may not be best practice. 但这可能不是最佳实践。 Your code will be like below 您的代码如下所示

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

<--Remaining view-->

</LinearLayout>
       </Scrollview>

And in Java on addmoreinfo button click call this scrollview like below:- 然后在Java中的addmoreinfo按钮上,单击调用此scrollview,如下所示:-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当内容超出视图时如何修复我的 LinearLayout 以向下滚动 - How to fix my LinearLayout to scroll down when content exceeds view 如何在单击按钮时将自定义布局添加到线性布局 - how do I add a custom layout to a Linear Layout on the click of a button 在线性布局中无法单击按钮 - Can't Click Button whilst in linear layout 线性布局不可见/重叠 - Linear Layout not visible / Overlapping Android:通过单击按钮在单个相对布局中创建两个linearlayout - Android: creating two linearlayout in single relative layout with on click button 如何在向上滚动启动时使晶圆厂可见,而在向下滚动启动时如何隐藏晶圆厂 - How to make fab visible when scroll up starting and hide when scroll down starting Android Studio-每次单击按钮时如何在线性布局上生成新的textview - Android Studio - How can I generate a new textview on my linear layout every time i click a button 线性布局不可见OnClickListener - Linear layout not getting visible OnClickListener 如何在线性布局中固定按钮位置 - How to fix the button position in Linear Layout 在 android 工作室中单击按钮创建线性布局可编程性 - Create Linear Layout programmability on button click in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM