Android: Box that fills entire screen with content below

Simon Sessingø

I've been trying to figure out how to place a container that fills the entire screen vertically inside a ScrollView that has content below.

Something like this:

  • [ BOX THAT FILLS ENTIRE SCREEN ]
  • [ Some other stuff / requires scroll to view ]

This is the content I would like below the box: http://myupload.dk/handleupload/ce34836ostt

I've tried everything - it seems like i can't position stuff absolute to the container that fills the entire screen. I can make a box that fills the entire screen, but everything i adds below it squeezes the box together.

It works when I add a size to the box, like this:

<com.github.ksoichiro.android.observablescrollview.ObservableScrollView

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|top"
    android:minWidth="25px"
    android:minHeight="0px"
    android:paddingTop="0dp"
    android:fillViewport="true"
    android:id="@+id/scroll">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <!-- THIS BOX I WOULD LIKE TO FIT THE ENTIRE SCREEN -->

        <android.support.v4.view.ViewPager
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:id="@+id/cardsPager" />

        <!-- THIS CONTENT SHOULD BE BELOW THE BOX ABOVE -->

        <fragment android:name="bonnier.hvadsynes.fragments.DetailsFragment"
                  android:id="@+id/details_fragment"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>


    </LinearLayout>
</com.github.ksoichiro.android.observablescrollview.ObservableScrollView>

Really appreciate your help!

  • Simon
Silicide

My idea is to set the height of the screen-filling-box programmatically.

When and Where: depends on what you use e.g.in onResume there surely are better places but for now it works. How: add an OnGlobalLayoutListener to your viewtreeobserver and then copy your scrollviews height to 'the box'.

<!--Whatever the whole things height should be, e.g. match_parent or 100dp or or or-->
<ScrollView
     android:background="#0f0"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:id="@+id/scrollview">

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

         <!-- THIS BOX I WOULD LIKE TO FIT THE ENTIRE SCREEN -->
         <!-- Any height works as we overwrite it anyway-->
         <View
             android:id="@+id/makebig"
             android:background="#f00"
             android:layout_width="match_parent"
             android:layout_height="300dp" />

         <!-- THIS CONTENT SHOULD BE BELOW THE BOX ABOVE -->
         <View
             android:background="#0ff"
             android:id="@+id/details_fragment"
             android:layout_width="match_parent"
             android:layout_height="100dp"/>

     </LinearLayout>
 </ScrollView>

In your Activity or wherever: e.g. in onResume()

final View makebig = findViewById(R.id.makebig);
final View scrollview = findViewById(R.id.scrollview);

final ViewTreeObserver viewTreeObserver = scrollview.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        //only do this all once
        scrollview.getViewTreeObserver().removeOnGlobalLayoutListener(this);

        makebig.getLayoutParams().height = scrollview.getHeight();
    }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android: Relative layout content goes below screen

From Dev

Create a DIV that fills remainder of screen below variable height header

From Dev

xcode 5 UITableView always fills entire length of screen

From Dev

How to create a container that fills up entire screen with no padding in bootstrap 3?

From Dev

Full screen div with content below it in

From Dev

Entire nav bar overlapping the content below

From Dev

How do I insert an image in HTML so that its fills up the entire screen regardless of screen size?

From Dev

Split layout for HTML screen, content below not visible

From Dev

Android toolbar filling entire screen

From Dev

Create Section with Video Background That Fills Initial Viewport and Allows Content to Fall Below It

From Dev

NestedScrollView fills full screen

From Dev

Toolbar fills the whole screen

From Dev

NestedScrollView fills full screen

From Dev

Toolbar fills the whole screen

From Dev

Input box not filling the entire space when the screen is small

From Dev

android webview taking up entire screen

From Dev

Android Camera Preview not display in entire screen

From Dev

Background not filling entire screen in scrollview android

From Dev

Android Content Box - custom listview

From Dev

Select the entire content of the "Find what" box in "Find and Replace" in Microsoft Excel

From Dev

Android WebView fit content to screen

From Dev

Replace screen content in Android with a ListActivity

From Dev

Calendar of DatePicker fills whole screen

From Dev

Javascript chart fills up the entire browser window

From Dev

Angular injected pages with long content make entire page load below the top of the page, cutting off the page title

From Dev

jQuery tabs- content in non active tab spanning entire page creating white space below footer

From Dev

Android: put element below another element and align at bottom of screen

From Dev

Android: put element below another element and align at bottom of screen

From Dev

Android SupportLib - FrameLayout in CoordinatorLayout with AppBarLayout consuming entire screen-height

Related Related

  1. 1

    Android: Relative layout content goes below screen

  2. 2

    Create a DIV that fills remainder of screen below variable height header

  3. 3

    xcode 5 UITableView always fills entire length of screen

  4. 4

    How to create a container that fills up entire screen with no padding in bootstrap 3?

  5. 5

    Full screen div with content below it in

  6. 6

    Entire nav bar overlapping the content below

  7. 7

    How do I insert an image in HTML so that its fills up the entire screen regardless of screen size?

  8. 8

    Split layout for HTML screen, content below not visible

  9. 9

    Android toolbar filling entire screen

  10. 10

    Create Section with Video Background That Fills Initial Viewport and Allows Content to Fall Below It

  11. 11

    NestedScrollView fills full screen

  12. 12

    Toolbar fills the whole screen

  13. 13

    NestedScrollView fills full screen

  14. 14

    Toolbar fills the whole screen

  15. 15

    Input box not filling the entire space when the screen is small

  16. 16

    android webview taking up entire screen

  17. 17

    Android Camera Preview not display in entire screen

  18. 18

    Background not filling entire screen in scrollview android

  19. 19

    Android Content Box - custom listview

  20. 20

    Select the entire content of the "Find what" box in "Find and Replace" in Microsoft Excel

  21. 21

    Android WebView fit content to screen

  22. 22

    Replace screen content in Android with a ListActivity

  23. 23

    Calendar of DatePicker fills whole screen

  24. 24

    Javascript chart fills up the entire browser window

  25. 25

    Angular injected pages with long content make entire page load below the top of the page, cutting off the page title

  26. 26

    jQuery tabs- content in non active tab spanning entire page creating white space below footer

  27. 27

    Android: put element below another element and align at bottom of screen

  28. 28

    Android: put element below another element and align at bottom of screen

  29. 29

    Android SupportLib - FrameLayout in CoordinatorLayout with AppBarLayout consuming entire screen-height

HotTag

Archive