0

I have seen a lot of answers of this question here, but none of them really worked for me (the only exception was bottom padding, which I consider an ugly workaround).

I have a ScrollView inside a LinearLayout inside Fragment. The last line (or so) of the content cannot be seen, since it is hidden behind the buttons.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment"
android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Medium Text"
    android:id="@+id/section_label"
    android:layout_weight="0"
    android:layout_gravity="center_horizontal" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/scrollView"
    android:layout_weight="1">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listLayout">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Text"
                android:id="@+id/textView"
                android:width="0px"
                android:layout_weight="0.8" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Text"
                android:id="@+id/textView2"
                android:width="0px"
                android:layout_weight="0.2" />
        </TableRow>

    </LinearLayout>
</ScrollView>

</LinearLayout>

This issue persists if I remove the "Medium text" TextView, so that's not the View that causes it. I have tried setting different layout_heights and layout_weights of all the Views that are supposed to stretch but I have had no luck so far.

Demonstration of the issue described, all the items are supposed to be doubled

Majlen
  • 1
  • 3
  • Umm, what `Button`s? And why do you have a `TableRow` without `TableLayout`? – Sourabh Mar 27 '16 at 15:59
  • I mean the android soft buttons. `TableLayout` did not change anything. – Majlen Mar 27 '16 at 16:18
  • If you're worried about using a constant for the bottom padding, you could set the bottom padding programmatically like this: http://stackoverflow.com/questions/8689117/dimension-of-soft-buttons-bar – Gi0rgi0s Mar 27 '16 at 16:53

3 Answers3

1

Set android:fillViewport="true" on ScrollView

Want2bExpert
  • 527
  • 4
  • 11
0

use it and check.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment"
android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Medium Text"
    android:id="@+id/section_label"
    android:layout_weight="0"
    android:layout_gravity="center_horizontal" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/scrollView"
    android:layout_weight="1">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listLayout">

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

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="New Text"
                android:id="@+id/textView"
                android:layout_weight="0.5" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="New Text"
                android:id="@+id/textView2"
                android:layout_weight="0.5" />
        </LinearLayout>

    </LinearLayout>
</ScrollView>

</LinearLayout>

I hope, it can help you.

Haniyeh Khaksar
  • 774
  • 4
  • 20
  • Unfortunately it still behaves the same. Last item is unable to be seen. I wonder if I am doing something horribly wrong... – Majlen Mar 27 '16 at 18:04
  • @Majlen I changed code, check it. if you have problem again please tell more details or show by picture. – Haniyeh Khaksar Mar 27 '16 at 18:11
  • I added an example in the original post. The LinearLayout was filled in programatically. Now I have created a static example with LinearLayout instead of TableRow as there is in your code, where the Last 2 TextViews contained different message, so it could be seen. The issue is still there as can be seen in this image: http://home.zcu.cz/~majlen/issue.png . – Majlen Mar 27 '16 at 18:37
  • Have you tried to create margin between that header and the listview? – Want2bExpert Mar 27 '16 at 22:34
0

Even though not perfect, a solution that worked for me was adding this code to onCreateView() method of Fragment:

int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
    statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    density = Math.ceil(getResources().getDisplayMetrics().density);
    realStatusBarHeight = (int) Math.ceil(statusBarHeight * density);
}
ScrollView scroll = (ScrollView) rootView.findViewById(R.id.scrollView);
scroll.setPadding(scroll.getPaddingLeft(), scroll.getPaddingTop(), scroll.getPaddingRight(), scroll.getPaddingBottom() + realStatusBarHeight);

Thanks @Gi0rgi0s for pointing me in the direction of status bar height.

Majlen
  • 1
  • 3