-1

我在 CoordinatorLayout 中有一个nestedScrollview。现在,nestedScrollview 中有 5-6 个视图,并且可见性会根据通过网络获得的数据而改变。问题是,当我隐藏任何视图的可见性时,滚动视图总是采用相同的高度(所有 5-6 个视图的总和)并在底部留下一个空白区域。谁能告诉我如何重新调整滚动视图的高度,以便滚动视图底部没有空白区域。

<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>

这是 NestedScrollview。下面是 profile_extra_details_layout。这种布局的可见性是根据网络的数据可用性以及正在查看其个人资料的用户类型来控制的。

<?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>

如果我需要在任何地方详细说明,请告诉我。

4

2 回答 2

0

这将对您有所帮助:当您隐藏视图时使用 View.GONE ,我认为您正在使用 View.INVISIBLE

于 2016-08-19T05:15:38.637 回答
0

尝试将 nestedscrollview 高度更改为 match_parent 并将子线性布局高度更改为 wrap_content。之后根据您的数据在运行时更改线性布局的子布局的可见性。

于 2016-08-19T06:09:38.633 回答