-1

I have a nestedScrollview inside a CoordinatorLayout. Now, there are 5-6 views inside nestedScrollview and there visibilty will change depending on the data available via network. The issue is that scrollview always takes the same height (total of all 5-6 views) and leaves a blank space at bottom when i hide visibility of any view. Could any one please tell me how I can readjust the height of the scrollview so there is no blank space at bottom of the scrollview.

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:id="@+id/MyAppbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:collapsedTitleGravity="center_horizontal"
        app:expandedTitleGravity="center_horizontal"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <!--Some content here-->

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

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

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

        <include
            android:id="@+id/profile_extra_details"
            layout="@layout/profile_extra_details_layout" />

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

            <include layout="@layout/divider" />

            <ViewSwitcher
                android:id="@+id/work_switcher"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <include
                    android:id="@+id/see_project_listing"
                    layout="@layout/photos_with_heading" />

                <TextView
                    android:id="@+id/txt_no_work_found"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:text="There are no Design Boards"
                    />
            </ViewSwitcher>

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

This is the NestedScrollview. Below is the profile_extra_details_layout. This the layout whose visibility is controlled based on data availability from network and also the type of user whose profile is being seen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include layout="@layout/divider" />

    <TextView
        android:id="@+id/user_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:visibility="gone" />

    <LinearLayout
        android:id="@+id/location_buget_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:orientation="horizontal"
        android:visibility="visible">

        <LinearLayout
            android:id="@+id/ll_budget_yearEstb"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:visibility="gone">

            <ImageView
                android:id="@+id/img_budget_yearEstb"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/id_proejct_budget" />

            <TextView
                android:id="@+id/txt_budget_yearEstb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_location"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:visibility="gone">

            <ImageView
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_gravity="center_horizontal"
                android:padding="5dp"
                android:src="@drawable/id_project_city" />

            <TextView
                android:id="@+id/location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:padding="5dp"
                android:text="Mumbai,India"
                android:textStyle="bold" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/individual_firm_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:visibility="gone">

        <ImageView
            android:layout_width="@dimen/image_size_beside_text"
            android:layout_height="@dimen/image_size_beside_text"
            android:src="@drawable/id_expert_firm_ind" />

        <TextView
            android:id="@+id/individual_firm_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Firm/Individual" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/awards_ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:visibility="gone">

        <ImageView
            android:layout_width="@dimen/image_size_beside_text"
            android:layout_height="@dimen/image_size_beside_text"
            android:src="@drawable/id_expert_awards" />

        <TextView
            android:id="@+id/awards_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
    </LinearLayout>

    <LinearLayout
        android:id="@+id/web_add_ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:visibility="gone">

        <ImageView
            android:layout_width="@dimen/image_size_beside_text"
            android:layout_height="@dimen/image_size_beside_text"
            android:src="@drawable/id_seller_web" />

        <TextView
            android:id="@+id/web_add_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Abc.xyz" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_location_ho"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:visibility="gone">

        <ImageView
            android:layout_width="@dimen/image_size_beside_text"
            android:layout_height="@dimen/image_size_beside_text"
            android:src="@drawable/id_project_city" />

        <TextView
            android:id="@+id/location_ho_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Abc.xyz" />
    </LinearLayout>
</LinearLayout>

Please let me know if I need to elaborate more anywhere.

user2601981
  • 137
  • 2
  • 8
  • Without any codes or image structure or something, we wont be able to assist you. That's why people are not caring about this. – Cyclopes Aug 19 '16 at 05:09
  • Try this, but wont guarantee whether this would be the fix in your case. http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/ – Cyclopes Aug 19 '16 at 05:12

2 Answers2

0

This would help you: when you hide your view use View.GONE , i think you are using View.INVISIBLE

VNS
  • 44
  • 8
  • No i am using View.GONe only. I dont want View.INVISIBLE because that will create white space in middle of the layout – user2601981 Aug 19 '16 at 05:33
  • Are you hiding views or linear layout? because you are using views inside linear layout – VNS Aug 19 '16 at 06:13
  • I am hiding both views as well as LinearLayout in case there is nothing to display inside that LinearLayout – user2601981 Aug 19 '16 at 08:28
0

Try to change nestedscrollview height to match_parent and the child linear layout height to wrap_content. After that according to you data change visibility of child layout of linear layout at run time.

Dhalloo
  • 115
  • 2
  • 12