这是我的activity_article_list.xml
<android.support.design.widget.CoordinatorLayout
...
android:fitsSystemWindows="true"
android:theme="@style/MyTheme">
<android.support.design.widget.AppBarLayout
...
android:fitsSystemWindows="true"
android:theme="@style/MyAppBarTheme">
<android.support.design.widget.CollapsingToolbarLayout
...
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include layout="@layout/activity_toolbar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
...
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.malinskiy.superrecyclerview.SuperRecyclerView
.../>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
这是activity_toolbar.xml
<android.support.v7.widget.Toolbar
...
android:id="@+id/list_toolbar"
android:elevation="4dp"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/MyTheme">
<RelativeLayout>
<ImageButton
... />
<ImageButton
.../>
<TextView
... />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
风格,MyTheme是Theme.AppCompat.Light.NoActionBar
,
和MyAppBarTheme是ThemeOverlay.AppCompat.ActionBar
。
我看到很多关于折叠工具栏的问题。
我认为我的xml类似于问题或讲座的内容。
我认为重点是layout_scrollFlags
,layout_collapseMode
,layout_scrollFlags
。
它仍然存在。
有MyAppBarTheme错误的父母吗?
或任何错误的代码?
修改:activity_article_list.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:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/MyTheme">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyAppBarTheme">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar
android:id="@+id/list_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="0dp"
android:background="@color/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="@style/MyTheme">
<TextView
android:id="@+id/boardName"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:textColor="@color/textColorPrimary"
android:textSize="20dp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.malinskiy.superrecyclerview.SuperRecyclerView
android:id="@+id/article_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/windowBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
这是对我的代码的引用,其中实现了折叠工具栏 试试这个。
<?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:background="@color/white"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<include layout="@layout/layout_toolbar"/>
<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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000"
>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="#0000"
app:layout_scrollFlags="enterAlways|scroll">
<include layout="@layout/home_menu_items"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout
android:id="@+id/hot_deals_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginRight="5dp"
android:padding="2dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<android.support.v7.widget.AppCompatTextView
android:layout_weight=".3"
android:id="@+id/pdt_info_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="1"
android:text="Hot Deals"
android:textSize="18dp"
android:gravity="start|center"
android:textStyle="bold"
android:textColor="@color/black_dark"
/>
<TextView
android:id="@+id/show_More"
android:layout_weight=".7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Show More"
android:gravity="right|center"
android:maxLines="1"
android:textSize="14dp"
android:textColor="@color/black_moderate"
/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:scrollbars="none" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>