【问题标题】:Android collapsing toolbar like Google play games appAndroid 折叠工具栏,如谷歌玩游戏应用
【发布时间】:2017-10-25 07:32:32
【问题描述】:

我正在尝试在我的应用程序中添加一个折叠工具栏,例如 Google play 游戏应用程序。请帮我实现这个。

这是我的布局代码:

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/htab_collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:titleEnabled="false">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax">
            <include
                layout="@layout/layout_header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
        </RelativeLayout>

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

        <android.support.design.widget.TabLayout
            android:id="@+id/htab_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:tabIndicatorColor="@android:color/black"
            app:tabSelectedTextColor="@android:color/black"
            app:tabTextColor="@android:color/black"
            android:background="@android:color/white"/>

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

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

<android.support.v4.view.ViewPager
    android:id="@+id/htab_viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

这是模型的链接: https://drive.google.com/file/d/0B96q57CU3elESmpsUFFBcHZaRzA/view?usp=sharing

应用链接: https://play.google.com/store/apps/details?id=com.google.android.play.games

【问题讨论】:

    标签: android material-design android-collapsingtoolbarlayout


    【解决方案1】:

    你可以这样使用

      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout
      android:id="@+id/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"
      tools:context=".activity.PlaceDetailsActivity">
    
      <android.support.design.widget.AppBarLayout
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_behavior="@string/ScrollingAppBarLayoutBehavior">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:title="Results"
            app:contentInsetStartWithNavigation="0dp"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="@dimen/anchor_point"
        android:fitsSystemWindows="true"
        android:background="@color/colorAccent"
        app:layout_behavior="@string/BackDropBottomSheetBehavior">
    </android.support.v4.view.ViewPager>
    
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:behavior_peekHeight="@dimen/bottom_sheet_peek_height"
        android:id="@+id/bottom_sheet"
        app:layout_behavior="@string/BottomSheetBehaviorGoogleMapsLike"
        app:anchorPoint="@dimen/anchor_point"
        app:behavior_hideable="false">
    
        <include
            layout="@layout/bottom_sheet_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"/>
    </android.support.v4.widget.NestedScrollView>
    
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/bottom_sheet"
        app:layout_anchorGravity="top|right|end"
        android:src="@drawable/directions_white_24dp"
        android:layout_margin="@dimen/fab_margin"
        app:layout_behavior="@string/ScrollAwareFABBehavior"
        android:clickable="true"/>
    
    <android.support.design.widget.AppBarLayout
        android:id="@+id/merged_appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:tag="modal-appbar"
        app:layout_behavior="@string/MergedAppBarLayoutBehavior">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <View
                android:id="@+id/background"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:background="@color/colorPrimary"
                android:layout_gravity="bottom"/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/expanded_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:contentInsetStartWithNavigation="0dp"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                app:title="@string/key_binding_default_toolbar_name"
                app:navigationIcon="@drawable/close_white_24dp"/>
        </FrameLayout>
         </android.support.design.widget.AppBarLayout>
         </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

    • 请让我知道“app:layout_behavior”
    • 在strint中写入包名点行为名,或者你可以直接在你的xml中写入行为并根据你的需要做
    猜你喜欢
    • 2015-12-10
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 2023-03-13
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多