-1

I know that this question is often ask but i don't find the way to do properly in my case.

As you can see in my xml file, i'm using CoordinatorLayout, NestedScrollView and AppBarLayout. When the nestedScrollview content is smaller than the screen height, it let blank extra space for nothing.

How can i remove this blank extra space?

Thanks for all

 <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hello World!" />

                <!-- more content but not enought to fill screen -->

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

        <android.support.design.widget.AppBarLayout
            android:id="@+id/main_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="200dp"
                        android:background="#ff0000">

                        <TextView
                            android:id="@+id/main_linearlayout_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="30dp"
                            android:layout_marginTop="30dp"
                            android:text="PSEUDO"
                            android:textColor="#ffffff"
                            android:textStyle="bold" />
                    </LinearLayout>


                </LinearLayout>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/main_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimaryDark">

<!-- some content (title) -->
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CoordinatorLayout>

Edit 1 :

  • Withou Scroll

enter image description here

  • With NestedScrollView height wrap_content

enter image description here

  • With NestedScrollView height match_parent (so it's the same probleme, instead to have blank space, it's pink but it rest a extra useless space)

enter image description here

So to be clear i want nothing under the last "Hello World" and don't scroll more than necessary.

Rémy
  • 241
  • 1
  • 16

2 Answers2

0

Set the height of your NestedScrollView to match_parent.

Mark Buikema
  • 2,211
  • 26
  • 51
-1

Set your NestedScrollView's height to match_parent. Set your LinearLayout's height to match_parent. Modify your TextView as

 <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="hello world"/>

Assign each TextView a height of 0dp and weight of 1.layout_weight specifies how much of the extra space in the layout to be allocated to the View.What this does is expand your TextViews equally into the remaining space(In this case it happens to be the complete screen).
Explanation in the official developers doc.

SynAck
  • 346
  • 2
  • 17