android android-support-library android-toolbar android-support-design

Cómo ocultar ToolBar cuando desplazo contenido hacia arriba en Android



android-support-library android-toolbar (4)

Envuelva activity_main.xml en el diseño del coordinador para que sea su diseño principal.

<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:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" /> </android.support.design.widget.CoordinatorLayout>

Estoy tratando de ocultar mi barra de herramientas cuando desplazo mi texto e imagen con contenido, aquí uso scrollView para obtener el contenido de desplazamiento cuando, cuando desplazo el contenido hacia arriba cómo ocultar la barra de herramientas, por favor, alguien me diga cómo obtener

aquí mi código XMl

content_main.XML

<android.support.v4.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:paddingTop="?android:attr/actionBarSize" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:id="@+id/textone" android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="23dp" android:textStyle="bold" android:text="hello world jheds sdjhs jds sjbs skjs ksjs kksjs ksj sdd dskd js sk "/> <ImageView android:id="@+id/imge" android:layout_width="match_parent" android:layout_height="250dp" android:src="@drawable/imag_bg"/> <TextView android:id="@+id/texttwo" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:text="Pretty good, the Toolbar is moving along with the list and getting back just as we expect it to. This is thanks to the restrictions that we put on the mToolbarOffset variable. If we would omit checking if it’s bigger than 0 and lower than mToolbarHeight then when we would scroll up our list, the Toolbar would move along far away off the screen, so to show it back you would have to scroll the list down to 0. Right now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the list all of the time and if we start scrolling down, we can see it immediately showing. up our list, the Toolbar would move along far away off the screen, so to show it back you would have to scroll the list down to 0. Right now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the list all of the time and if we start scrolling down, we can see it immediately showing up our list, the Toolbar would move along far away off the screen, so to show it back you would have to scroll the list down to 0. Right now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the list all of the time and if we start scrolling down, we can see it immediately showing up our list, the Toolbar would move along far away off the screen, so to show it back you would have to scroll the list down to 0. Right now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the list all of the time and if we start scrolling down, we can see it immediately showing up our list, the Toolbar would move along far away off the screen, so to show it back you would have to scroll the list down to 0. Right now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the list all of the time and if we start scrolling down, we can see it immediately showing up our list, the Toolbar would move along far away off the screen, so to show it back you would have to scroll the list down to 0. Right now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the list all of the time and if we start scrolling down, we can see it immediately showing It works pretty well, but this is not what we want. It feels weird that you can stop it in the middle of the scroll and the Toolbar will stay half visible. Actually this is how it’s done in Google Play Games app which I consider as a bug It works pretty well, but this is not what we want. It feels weird that you can stop it in the middle of the scroll and the Toolbar will stay half visible. Actually this is how it’s done in Google Play Games app which I consider as a bug It works pretty well, but this is not what we want. It feels weird that you can stop it in the middle of the scroll and the Toolbar will stay half visible. Actually this is how it’s done in Google Play Games app which I consider as a bug."/> </LinearLayout> <View android:layout_width="wrap_content" android:layout_height="30dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:text="hai" android:layout_width="160dp" android:layout_height="match_parent" /> <Button android:text="hello" android:layout_width="160dp" android:layout_height="match_parent" /> </LinearLayout>

actividad_principal.XML

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" />


Este es el mejor escenario para utilizar CoordinatorLayout en su aplicación. CoordinatorLayout es un FrameLayout súper potente que tiene muchos ingeniosos trucos de animación en sus mangas.

La biblioteca de diseño presenta CoordinatorLayout, un diseño que proporciona un nivel adicional de control sobre los eventos táctiles entre las vistas secundarias, algo que aprovechan muchos de los componentes de la biblioteca de diseño.

Puede comenzar con this y this tutorial.


Puede encontrar mi solución sobre su pregunta desde aquí: Barra de herramientas de Android + Diseño de pestaña + Cajón, Ocultar barra de herramientas al desplazarse y llevar TabLayout a la parte superior

Esta es una solución funcional, pero no es la mejor manera de implementar esta animación. Con CoordiantorLayout puede relacionar sus puntos de vista y sus comportamientos de desplazamiento.

Puede encontrar más información aquí: https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html

Cuando tenga tiempo, intentaré publicar un código de ejemplo para ti.


tienes que hacer muchos cambios en ambos diseños. primero use CoordinatorLayout en activity_main.XML como a continuación (cambie el tema según sus requisitos).

<?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/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" 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" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" /> </android.support.design.widget.CoordinatorLayout>

en content_main.XML use android.support.v4.widget.NestedScrollView lugar de ScrollView .

también use app:layout_behavior="@string/appbar_scrolling_view_behavior" dentro de android.support.v4.widget.NestedScrollView como se muestra a continuación.

<android.support.v4.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/textone" android:layout_width="match_parent" android:layout_height="match_parent" android:text="hello world jheds sdjhs jds sjbs skjs ksjs kksjs ksj sdd dskd js sk " android:textSize="25dp" android:textStyle="bold" /> /// Add your other code here </LinearLayout> </android.support.v4.widget.NestedScrollView>