5
votes

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
Have you tried setting ScrollView and LinearLayout's height with wrap_content. And why do you add toString(), I think Html.fromHtml() works ok. - L. Swifter
I set ScrollView height and LinearLayout height to wrap_content, but am still getting the same problem. Also, I call toString() on Html.fromHtml() because the response contains <a> tags on certain words and highlights them because of it. I did not want that to happen. - Crazy_K
I ended up doing a hack where I appended a bunch of new lines in this manner tvAbilities.setText(Html.fromHtml(abilities).toString().concat("\n\n\n\n"); It's really ugly, but I couldn't figure out a way to make it scroll all the way to the last few lines of my tvAbilities textview. - Crazy_K

1 Answers

7
votes

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

Instead of ScrollView use NestedScrollView

Check the answer that helped me.