Search code examples
androidandroid-linearlayoutandroid-relativelayoutandroid-scrollview

Last LinearLayout of a RelativeLayout inside a scroll view is not displayed


First of all, I roamed the web for an answer, but wasn't able to fix my problem.

I have the following scroll view inside a layout:

<ScrollView 
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <ImageView
            android:id="@+id/img_cover_picture"
            android:layout_width="128dp"
            android:layout_height="128dp"
            android:layout_centerHorizontal="true"

            android:layout_marginBottom="12dp"/>

        <LinearLayout 
            android:id="@+id/list_flags"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignBottom="@id/img_cover_picture"
            android:layout_marginBottom="-12dp"
            android:orientation="horizontal"
             />

        <TextView
            android:id="@+id/txt_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/img_cover_picture"
            android:gravity="center_horizontal"
            android:textColor="#F5F5F5"
            android:textSize="28sp" />

        <TextView 
            android:id="@+id/list_infos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/txt_title"
            android:textColor="#BABBBB"
             />

        <LinearLayout 
            android:id="@+id/view_blog_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/list_infos"
            android:layout_marginTop="8dp"
            android:orientation="horizontal"
             />


        <TextView
            android:id="@+id/txt_description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/view_blog_count"
            android:gravity="center_horizontal"
            android:textColor="#F5F5F5"
            android:textSize="18sp" />

        <LinearLayout 
            android:id="@+id/list_categories"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/txt_description"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:orientation="horizontal"
             />



    </RelativeLayout>

</ScrollView>

The empty LinearLayouts are filled programatically.

What I expect is that when the content displayed in the RelativeLayout is too big, the ScrollView allows the user to scroll to see all the content.

Problem is: when it happens, he can scroll, but the last LinearLayout (identified by list_categories) is never displayed. I have tried all sort of things:

  • Maybe as it is filled programatically it was empty? I tried to put it below @id/view_blog_count to check, and it was displayed (overlaying the description)
  • I tried to use set fillViewport to true
  • I tried to change the weights
  • I tried to play with the layout(_width|_height)
  • ...

No success so far :(

Thanks for your help!

Gaaston


UPDATE

I know the LinearLayouts are empty, but they are filled programatically (and I'm sure they are). And besides, I tried to add a TextView in the empty LinearLayout as a test but the LinearLayout was still hidden.


UPDATE 2

I'm using a RelativeLayout so that the flags (list_flags) are over the cover picture (img_cover_picture). However as @lelloman suggested I did try with a horizontal LinearLayoout instead. It still did not work :)


Solution

  • Found a tweak that did the trick:

    At the end of the RelativeLayout inside the ScrollView, I added the following element.

            <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/list_categories"
            android:visibility="invisible"
            android:text="TEST"/>
    

    And.. it worked, the last linear layout is now there. Looks like it's really the last view that is not displayed.

    Now I know that it is tweak, so I won't validate this yet, in case someone comes up with a cleaner idea. But if anyone is stuck with that, this is the best I found!

    Thanks anyway for the help guys :)

    Cheers

    Gaaston