2015-08-17 49 views
0

我有一个带有NavigationDrawer和工具栏的活动。当我想要在子片段视图之一滚动时消失一个toobar时,我正面临一个问题。一切工作正常,但有一些视图从底部出现,其大小与正在消失的工具栏完全相同。在android中滚动时隐藏工具栏

我做了一个显示问题的GIF动画。由于我的名誉我不能直接发布图像,但this gifthis gif显示问题

我试图找出这是从哪里来。它似乎来自我的容器FrameLayout,其中我的片段视图放置在运行时。我将其背景更改为绿色,以便我可以识别它。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

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

    <include 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_scrollFlags="scroll|enterAlways" 
     layout="@layout/toolbar" /> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/darkGreen" 
     tools:context="org.cddevlib.breathe.MainActivity" /> 
</LinearLayout> 

<fragment 
    android:id="@+id/navigation_drawer" 
    android:name="org.cddevlib.breathe.NavigationDrawerFragment" 
    android:layout_width="@dimen/navigation_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    tools:layout="@layout/fragment_navigation_drawer" /> </android.support.v4.widget.DrawerLayout> 

这是工具栏的布局,包括

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    app:layout_collapseMode="pin" 
    app:layout_scrollFlags="scroll|enterAlways" 
    android:fitsSystemWindows="true" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 
</android.support.v7.widget.Toolbar> 

最后从片段片段查看加载:

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appBarLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/black" > 

    <include 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_scrollFlags="scroll|enterAlways" 
    layout="@layout/toolbar" /> 

    <android.support.v4.widget.NestedScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:background="@color/white" 
     android:fillViewport="true" > 

     (...) 

请注意,我包括在该布局中的工具栏,因为我想要我的应用程序中的每个片段不同的工具栏b隐藏/添加工具栏。

toolbar = (Toolbar) ((View) vw).findViewById(R.id.toolbar); 
      if (toolbar != null) { 
       // // for crate home button 
       activity = (AppCompatActivity) getActivity(); 
       activity.getSupportActionBar().hide(); 
       toolbar.setBackgroundDrawable(new ColorDrawable((ColorUtils.getColorDark(DataModule.getInstance() 
         .getMainActivity())))); 
       activity.setSupportActionBar(toolbar); 
       activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
      } 

SOLUTION

所以感谢萨纳特舒克拉答案firgured,我的问题是,我用了一个AppBarLayout太多我的碎片查看。在我的片段视图中,AppBarLayout是我所有组件的主要布局,但它不应该!它的目的是保存工具栏的内容!谢谢

回答

0

这不是问题。这是由android提供的很酷的动画和支持。当您使用工具栏使用协调员布局时,它将在滚动列表时显示出酷炫的动画。

设计库借此更上一层楼:使用AppBarLayout 让您的工具栏和其他视图(如 TabLayout提供标签)反应滚动事件打上 ScrollingViewBehavior

同级视图

阅读从这里开始: http://android-developers.blogspot.in/2015/05/android-design-support-library.html

如果你不想隐藏自己的工具栏,然后不使用统筹布局,并与工具栏appbar。

尝试此片段:

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

    <! -- Your Scrollable View --> 
    <android.support.v4.widget.NestedScrollView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/scrollView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:background="@color/white" 
      android:fillViewport="true" > 
    <android.support.v4.widget.NestedScrollView/> 
    <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
    <include 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|enterAlways" 
      layout="@layout/toolbar" /> 
    </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.CoordinatorLayout> 
+0

其实我想,动画,但我不希望在底部的绿色条,如下所示http://i.stack.imgur.com/Pe5Tl.gif。 –

+0

它不是一个酒吧。它的你的framelayout – SANAT

+0

@Christian Dud检查我编辑的答案。 – SANAT

相关问题