Android:NestedScrollView中的FrameLayout全屏显示

时间:2015-12-22 06:15:58

标签: android material-design

我正在实施可折叠工具栏。我的布局就像

<CoordinatorLayout>

    <AppBarLayout>
        <CollapsingToolbarLayout>
            <ImageView/>
            <Toolbar/>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clipToPadding="false"
     android:background="@android:color/white">

     <FrameLayout
         android:id="@+id/container_body"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

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

</CoordinatorLayout>

问题是如果我在FrameLayout内膨胀片段,它需要全屏我不想要。

我尝试用假LinearLayout代替FrameLayout给出硬编码高度它工作正常

xml代码:

<?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:fitsSystemWindows="true"
    android:background="@color/text_grey_color">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:expandedTitleGravity="center_horizontal|top"

            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            android:fitsSystemWindows="true">

         <include layout="@layout/profile_detail_include_layout"
             android:fitsSystemWindows="true"
             app:layout_collapseMode="parallax"
             />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

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

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




        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:background="@android:color/white"
            android:fillViewport="true"

            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/container_body"/>


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



    <de.hdodenhof.circleimageview.CircleImageView

        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/jack_example"
        android:id="@+id/circleView"
        app:civ_border_width="2dp"
        app:layout_anchor="@id/collapsing_toolbar"
        app:layout_anchorGravity="bottom|center"
        app:theme="@style/ThemeOverlay.AppCompat.Light"
        app:civ_border_color="@android:color/white"/>


</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

试试这段代码

<android.support.v4.widget.NestedScrollView 
 android:id="@+id/scroll"
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:clipToPadding="false"
 android:background="@android:color/white">

   <RelativeLayout 
     android:id="@+id/relative_layout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     >
 <FrameLayout
     android:id="@+id/container_body"
     android:layout_width="match_parent"
     android:layout_height="match_parent" />
   </RelativeLayout>

然后指定FrameLayout的大小