Android scroll view does not scroll all the way down

故事扮演 提交于 2020-01-25 06:46:31

问题


I have looked at many questions, but none of the solutions listed solved my problems: 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

I have an app with the following layout that contains a LinearLayout within a ScrollView

<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>

Basically, this layout is is being used for a Fragment. Inside that fragment, I call settext for tvPowers and tvAbilities, with Strings I get from querying a website.

Here is a snippet

    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;
}

Here is a screenshot of my scroll view not scrolling down all the way Picture

I have tried messing with ScrollView's width and height as both match_parent and wrap_content. I have also toggled fillViewPort between true and false. I took off all the padding for my elements and still get the same problem.


回答1:


I had the same problem and this solution worked for me:

Instead of ScrollView use NestedScrollView

Check the answer that helped me.



来源:https://stackoverflow.com/questions/38909726/android-scroll-view-does-not-scroll-all-the-way-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!