gpt4 book ai didi

android - android 向上滚动时自动隐藏或显示工具栏

转载 作者:行者123 更新时间:2023-11-29 00:52:13 25 4
gpt4 key购买 nike

我想在向上滚动隐藏和向下滚动显示时隐藏工具栏。使用 XML

app:layout_scrollFlags="scroll|enterAlways|snap"

在工具栏中。请帮我找出我需要的实际输出。滚动到顶部时工具栏必须隐藏并在向下滚动时显示。

<?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:layout_height="match_parent"
android:fitsSystemWindows="true">

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

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="275dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<ImageView
android:id="@+id/ivTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/apple_1"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:padding="5dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay">

<ImageView
android:id="@+id/ivBack"
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/icon_back_custom"
android:tint="@color/colorPrimary" />
</android.support.v7.widget.Toolbar>

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

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@android:color/transparent"
app:tabBackground="@android:color/transparent"
app:tabIndicatorColor="@android:color/black"
app:tabIndicatorHeight="2.50dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:tabMode="fixed"
app:tabPadding="0dp"
app:tabSelectedTextColor="@android:color/black"
app:tabTextColor="@android:color/holo_blue_dark" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<TextView
android:id="@+id/tvTitleTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|center_vertical"
android:padding="10dp"
android:text="TabSelection"
android:textAlignment="viewStart"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

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

sample

我怎样才能做到这一点?我想在向上滚动隐藏和向下滚动显示时隐藏工具栏。请帮我找出我需要的实际输出。滚动到顶部时工具栏必须隐藏并在向下滚动时显示。

最佳答案

我找到了解决方案:只需使用 app:layout_scrollFlags="scroll|enterAlways" 在 Layout 中创建您的工具栏和 imageView像这样

           <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
//ImageView
//Toolbar
</RelativeLayout>

完整代码:

    <?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:layout_height="match_parent"
android:fitsSystemWindows="true">

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

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="275dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<ImageView
android:id="@+id/ivTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_search"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />

<<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:background="@color/blue_cerulean_"
android:padding="5dp"
app:popupTheme="@style/AppTheme.PopupOverlay">

<ImageView
android:id="@+id/ivBack"
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_search"
android:tint="@color/colorPrimary" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>


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

<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@android:color/transparent"
app:tabBackground="@android:color/transparent"
app:tabIndicatorColor="@android:color/black"
app:tabIndicatorHeight="2.50dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:tabMode="fixed"
app:tabPadding="0dp"
app:tabSelectedTextColor="@android:color/black"
app:tabTextColor="@android:color/holo_blue_dark" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<TextView
android:id="@+id/tvTitleTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start|center_vertical"
android:padding="10dp"
android:text="TabSelection"
android:textAlignment="viewStart"
android:textColor="@color/colorAccent"
android:textSize="20sp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

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

关于android - android 向上滚动时自动隐藏或显示工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58318670/

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