【问题标题】:Android: FrameLayout inside NestedScrollView takes full screenAndroid:NestedScrollView 内的 FrameLayout 采用全屏模式
【发布时间】:2015-12-22 15:20:27
【问题描述】:

我正在实现可折叠工具栏。我的布局是这样的

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

【问题讨论】:

  • FrameLayout 将其子级放置在按层次结构堆叠的层中。要做你想做的事,你应该在一个位于框架布局内的 LinearLayout 中膨胀片段。
  • 试过不行。同样的问题
  • 当你说它需要全屏时,这是否意味着你看不到 AppBar 里面有 Toolbar 和 Imageview?
  • 你能把你完整的xml代码放在这里吗?
  • layout_height 父级的 layout_height 属性是什么?你想在你的片段中填充什么?可以是固定高度吗?

标签: android material-design


【解决方案1】:

试试这个代码

<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的大小

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多