当 linearLayout 在按钮上可见时如何向下滚动线性布局单击 [kotlin]
How to Scroll Down Linear Layout When linearLayout is visible on button click [kotlin]
我在滚动视图中有一堆文本视图和编辑文本表单,并且在同一滚动视图中还有一个线性布局下方表单,在此线性布局中有一堆文本视图垂直。当用户按下 "add more info" 时,最初线性布局的可见性消失了,它就在这个线性布局之上,按钮然后布局可见性是可见的。这按预期工作正常,但我想要的是当线性布局可见时,滚动视图应向下滚动,以便用户可以看到扩展数据。我尝试了所有但没有什么可以帮助我。
请帮我解决this.Below是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")
}
}
您可以解决此问题,在 xml 文件中的 exapandLinearLayout 之前添加另一个滚动视图,并在单击按钮时调用此滚动视图,这样您的线性布局就会向下滚动。但这可能不是最佳做法。
您的代码将如下所示
<Scrollview
android:id = @+id/scrollViewLayout
.....
....>
<LinearLayout....>
<--Remaining view-->
</LinearLayout>
</Scrollview>
然后在 Java 添加更多信息按钮上单击调用此滚动视图,如下所示:-
fun showHideLayout() {
if(linearLayoutAddMoreInfoExpand.visibility == GONE){
linearLayoutAddMoreInfoExpand.visibility = VISIBLE
mTextViewAddMoreInfo.setText("Close Add More Info")
scrollViewLayout.post(Runnable { scrollView.fullScroll(ScrollView.FOCUS_DOWN) })
我在滚动视图中有一堆文本视图和编辑文本表单,并且在同一滚动视图中还有一个线性布局下方表单,在此线性布局中有一堆文本视图垂直。当用户按下 "add more info" 时,最初线性布局的可见性消失了,它就在这个线性布局之上,按钮然后布局可见性是可见的。这按预期工作正常,但我想要的是当线性布局可见时,滚动视图应向下滚动,以便用户可以看到扩展数据。我尝试了所有但没有什么可以帮助我。 请帮我解决this.Below是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")
}
}
您可以解决此问题,在 xml 文件中的 exapandLinearLayout 之前添加另一个滚动视图,并在单击按钮时调用此滚动视图,这样您的线性布局就会向下滚动。但这可能不是最佳做法。 您的代码将如下所示
<Scrollview
android:id = @+id/scrollViewLayout
.....
....>
<LinearLayout....>
<--Remaining view-->
</LinearLayout>
</Scrollview>
然后在 Java 添加更多信息按钮上单击调用此滚动视图,如下所示:-
fun showHideLayout() {
if(linearLayoutAddMoreInfoExpand.visibility == GONE){
linearLayoutAddMoreInfoExpand.visibility = VISIBLE
mTextViewAddMoreInfo.setText("Close Add More Info")
scrollViewLayout.post(Runnable { scrollView.fullScroll(ScrollView.FOCUS_DOWN) })