amirhossein ramazani amirhossein ramazani - 4 months ago 10
Android Question

Scroll View not work properly with padding

I have a problem in my

Activity
. The
ScrollView
doesn't scroll down to the bottom.
Here's my XML layout of the
ScrollView
:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/test"
android:paddingRight="@dimen/layoutsPadding"
android:paddingTop="@dimen/layoutsPadding"
android:paddingLeft="@dimen/layoutsPadding"
android:paddingBottom="@dimen/scrollViewLayoutsPadding">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tab_introduction_background"
android:orientation="vertical"
android:padding="@dimen/layoutsPadding">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tab_introduction_title"
android:textSize="@dimen/bigFont"></TextView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/gap_titleAndText">
</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tab_introduction_description"
android:textSize="@dimen/smallFont"></TextView>
</LinearLayout>

</ScrollView>


What Can I do?

Answer

Since removing LinearLayout's padding worked, but you want it to have padding, why not just surround it with another LinearLayout and let only this outer LinearLayout to have a padding. And remove the inner LinearLayout's padding. This is probably not a very good style, but worth a try.

If you want to avoid this, you can also try removing the padding from the LinearLayout and adding a margin to all it's children.

EDIT: Since you really need that padding, adding an empty view at the bottom will definitely solve your problem, but it's not a good solution either:

<View
android:layout_width="fill_parent"
android:layout_height="30dp" />