gpt4 book ai didi

android - 使用 CoordinatorLayout 在 fragment 中隐藏 Activity 中的工具栏

转载 作者:行者123 更新时间:2023-11-29 20:14:00 24 4
gpt4 key购买 nike

美好的一天,我有一个带有 ToolbarViewPagerHomeActivity。在 ViewPager 中有 FragmentRecyclerView。我想在 Fragment 中隐藏 ToolBar onScrolling RecyclerView。我使用 CoordinatorLayout 进行了此操作,但它不起作用。有什么想法吗?

activity_home.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.HomeActivity">

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

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

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"/>

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


<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:pstsIndicatorColor="@color/mantis"/>

<android.support.v4.view.ViewPager
android:id="@+id/vpPager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"/>
</LinearLayout>


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

fragment_home.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragments.BusFragment">
<!-- TODO: Update blank fragment layout -->

<android.support.v7.widget.RecyclerView
android:id="@+id/busRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>


</FrameLayout>

我认为我应该对 RecyclerView 进行操作,就像在 ViewPager 中一样

app:layout_behavior="@string/appbar_scrolling_view_behavior"

也许可以选择以编程方式制作它?还是我的想法一点都不好?无论如何,谢谢你!

最佳答案

删除 LinearLayout 作为 AppBarLayout 的父级,并将 PagerSlidingTabStrip 移到 AppBarLayout 中。

<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"
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:id="@+id/appBarLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"/>

<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:pstsIndicatorColor="@color/mantis"/>

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

<android.support.v4.view.ViewPager
android:id="@+id/vpPager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"/>

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

关于android - 使用 CoordinatorLayout 在 fragment 中隐藏 Activity 中的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34330507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com