gpt4 book ai didi

java - 为什么不能以编程方式滚动 ScrollView?

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

我想以编程方式滚动 ScrollView 但我不能。

没有 ScrollView 方法“scrollToarrowScrollpageScrollfullScroll “不起作用!

final ScrollView scrollView = (ScrollView) view.findViewById(R.id.scrollbar_textchat);
Button sendButton = (Button) view.findViewById(R.id.btn_send);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});

xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--main-->
<ScrollView
android:id="@+id/scrollbar_textchat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:verticalScrollbarPosition="left"
android:fillViewport="true">
<!--messages list-->
<ListView
android:id="@+id/list_textchat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:cacheColorHint="@android:color/transparent" />
</ScrollView>
<!--/main-->

<!--line-->
<LinearLayout
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="2dp"
android:background="#FFEEEEEE"/>

<!--already Typing message...-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">

<com.salamatyar.components.TypingAnimationView
android:id="@+id/typing_textchat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"/>

<TextView
android:id="@+id/text_typing_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="typing" />

</LinearLayout>
<!--/already Typing message...-->

<!--line-->
<LinearLayout
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="2dp"
android:background="#FFEEEEEE"/>

<!--type-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>

<Button
android:id="@+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"/>

</LinearLayout>
<!--/type-->
</LinearLayout>

</LinearLayout>

最佳答案

试试这个代码:

 final ScrollView scrollView = (ScrollView) view.findViewById(R.id.scrollbar_textchat);
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}
});

使用ListView:滚动到底部位置

  listView.post(new Runnable(){
public void run() {
listView.setSelection(listView.getCount() - 1);
}});

关于java - 为什么不能以编程方式滚动 ScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42201422/

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