[英]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.