gpt4 book ai didi

java - 当线性布局在按钮单击上可见时如何向下滚动线性布局 [kotlin]

转载 作者:行者123 更新时间:2023-12-02 10:15:27 25 4
gpt4 key购买 nike

我在 ScrollView 内有一堆 TextView 和编辑文本表单,并且在同一 ScrollView 内的表单下方还有一个线性布局,在此线性布局中具有垂直的一堆 TextView 。最初,当用户按下“添加更多信息”时,线性布局的可见性消失,该信息就在此线性布局上方,按钮然后布局可见性可见。这按预期工作正常,但我想要的是当线性布局可见时, ScrollView 应该向下滚动,以便用户可以看到扩展数据。我尝试了一切,但没有任何东西可以帮助我。请帮我解决这个问题。下面是 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 ,并在单击按钮时调用此 ScrollView ,以便每当您的线性布局时它都会向下滚动。但这可能不是最佳实践。您的代码如下所示

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

<--Remaining view-->

</LinearLayout>
</Scrollview>

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

关于java - 当线性布局在按钮单击上可见时如何向下滚动线性布局 [kotlin],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54716405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com