【问题标题】:Android scroll view does not scroll all the way downAndroid滚动视图不会一直向下滚动
【发布时间】:2016-08-12 04:06:04
【问题描述】:

我查看了很多问题,但列出的解决方案都没有解决我的问题:Scrollview doesn't scroll to the margin at the bottom

ScrollView doesn't scroll to the bottom

(Android) ScrollView won't scroll all the way to the bottom of my LinearLayout

我有一个具有以下布局的应用,其中包含一个 ScrollView 中的 LinearLayout

<ScrollView android:id="@+id/Scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">

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

    <TextView
        android:padding="8dp"
        android:id="@+id/tvPowersLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Powers"
        android:textSize="20dp"
        android:textStyle="bold"
        />
    <TextView
        android:padding="8dp"
        android:id="@+id/tvPowers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12dp"
        android:text="Placeholder for powers"
        />

    <TextView
        android:padding="8dp"
        android:textSize="20dp"
        android:textStyle="bold"
        android:text="Abilities"
        android:id="@+id/tvAbilitiesLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

    <TextView
        android:padding="8dp"
        android:id="@+id/tvAbilities"
        android:layout_width="wrap_content"
        android:text="placeholder for abilities"
        android:layout_height="wrap_content"
        android:textSize="12dp"
        />

</LinearLayout>
</ScrollView>

基本上,这种布局被用于片段。在该片段中,我将 settext 称为 tvPowers 和 tvAbilities,并使用通过查询网站获得的字符串。

这是一个sn-p

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scrollview,container,false);;

    TextView tvPowers = (TextView) view.findViewById(R.id.tvPowers);
    TextView tvAbilities = (TextView) view.findViewById(R.id.tvAbilities);


    tvPowers.setText(Html.fromHtml(powers).toString());
    tvAbilities.setText(Html.fromHtml(abilities).toString());

    return view;
}

这是我的滚动视图没有一直向下滚动的屏幕截图 Picture

我尝试将 ScrollView 的宽度和高度作为 match_parent 和 wrap_content 来处理。我还在 true 和 false 之间切换了 fillViewPort。我删除了元素的所有填充,但仍然遇到同样的问题。

【问题讨论】:

  • 你试过用wrap_content设置ScrollView和LinearLayout的高度。还有为什么要加toString(),我觉得Html.fromHtml()可以。
  • 我将 ScrollView 高度和 LinearLayout 高度设置为 wrap_content,但仍然遇到同样的问题。另外,我在 Html.fromHtml() 上调用 toString() 是因为响应包含某些单词上的 标记并因此突出显示它们。我不希望这种情况发生。
  • 我最终做了一个 hack,我以这种方式添加了一堆新行 tvAbilities.setText(Html.fromHtml(abilities).toString().concat("\n\n\n\ n"); 这真的很难看,但我想不出一种方法让它一直滚动到我的 tvAbilities textview 的最后几行。

标签: android scrollview


【解决方案1】:

我遇到了同样的问题,这个解决方案对我有用:

用NestedScrollView代替ScrollView

查看对我有帮助的answer。

【讨论】:

    猜你喜欢
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    相关资源
    最近更新 更多