【问题标题】:how to hide toolbar in layout having framelayout, fragment drawer layout in activity and scrollview in corresponding fragment如何在具有框架布局的布局中隐藏工具栏,活动中的片段抽屉布局和相应片段中的滚动视图
【发布时间】:2016-01-07 07:44:40
【问题描述】:

这是我的活动 xml。滚动时什么都没有发生。我需要工具栏在用户开始滚动时消失,并在滚动到顶部时显示。

    <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/parent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/post_ad_bg"
            android:orientation="vertical">

            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/AppTheme.AppBarOverlay">

                <include
                    layout="@layout/toolbar_homepage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </android.support.design.widget.AppBarLayout>

            <com.abc.customviews.CustomDrawerLayout
                android:id="@+id/drawer_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <FrameLayout
                    android:id="@+id/container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                  app:layout_behavior="@string/appbar_scrolling_view_behavior" />

                <fragment
                    android:id="@+id/navigation_drawer"
                    android:name="com.fragments.SideMenuFragment"
                    android:layout_width="@dimen/navigation_drawer_width"
                    android:layout_height="match_parent"
                    android:layout_gravity="start" />

            </com.abc.customviews.CustomDrawerLayout>

        </LinearLayout>

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

这是我的片段 xml,我在其中有一个滚动视图。我尝试用 Nestedscrollview 替换,但仍然无法正常工作。任何帮助表示赞赏。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="none">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/parentLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false"
            android:orientation="vertical">

        </LinearLayout> 

    </ScrollView>

    <RelativeLayout
        android:id="@+id/rlProgressBar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_transparent_50"
        android:visibility="gone">

        <ProgressBar
            android:layout_width="@dimen/dimen_100_dp"
            android:layout_height="@dimen/dimen_100_dp"
            android:layout_centerInParent="true"
            android:indeterminateDrawable="@drawable/custom_progress_background" />

    </RelativeLayout>
</RelativeLayout>

【问题讨论】:

  • 您是否尝试将 'app:layout_behavior="@string/appbar_scrolling_view_behavior"' 放到 'CustomDrawerLayout' 中?
  • 是的。我已经试过了。行为没有变化。

标签: android toolbar android-framelayout android-coordinatorlayout android-appbarlayout


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:gravity="center"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    tools:context=".DashboardActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar_main"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#E4171212"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/AppTheme.PopupOverlay"

            />



    </com.google.android.material.appbar.AppBarLayout>

        <FrameLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_below="@id/appbar" />



        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:layout_gravity="bottom"
            android:id="@+id/navigation"
            app:labelVisibilityMode="labeled"
            android:background="?android:attr/windowBackground"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:menu="@menu/menu_nav"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>



</RelativeLayout>

【讨论】:

    【解决方案2】:

    像这样将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到您的 FrameLayout 中

        <FrameLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
             />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      相关资源
      最近更新 更多