gpt4 book ai didi

android - ScrollView,我无法滚动查看内容的顶部

转载 作者:行者123 更新时间:2023-11-30 00:17:42 25 4
gpt4 key购买 nike

我在 ScrollView 中有一个 LinearLayoutlayout_gravity="bottom"

问题是当内容到达 ScrollView 的顶部时,我无法滚动查看此内容的顶部。

Problem 1


我只能滚动查看屏幕底部,但我只能看到空白区域。

problem 2


这是我的布局 XML 代码:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.projects.zak_dev.errors.MainActivity">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">

<LinearLayout
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/content" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>

谁能帮帮我!

最佳答案

你必须删除 android:layout_gravity="bottom"

要到达 ScrollView 的底部,请将 android:id="@+id/scrollView" 添加到您的 ScrollView xml 标记中,然后只需将以下代码添加到您的 onCreate 函数或在设置文本后需要它的任何其他地方。

final ScrollView scrollView = ((ScrollView) findViewById(R.id.scrollView));
scrollView.postDelayed(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
},100);

您可以像这样尝试使用 post() 而不是 postDelayed():

final ScrollView scrollView = ((ScrollView) findViewById(R.id.scrollView));
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});

它没有延迟,但在某些情况下可能会导致问题。

关于android - ScrollView,我无法滚动查看内容的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46933715/

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