7

Sto cercando di nascondere la mia barra degli strumenti quando faccio scorrere il testo e l'immagine con il contenuto, qui uso scrollView per ottenere il contenuto di scorrimento quando, quando faccio scorrere il contenuto fino a come nascondi barra degli strumenti favore, qualcuno mi dica come ottenereCome nascondere ToolBar quando eseguo lo scorrimento del contenuto in Android

qui il mio codice 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> 

activity_main.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" /> 

here my image

+0

Prova questo, https: //mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-quando-list-is-scrolling% 28part3% 29/ –

+0

Non sto usando Listview e il pulsante di azione mobile qui @KNeerajLal – chanti

risposta

19

devi fare molte modifiche in entrambi i layout. prima usare CoordinatorLayout in activity_main.XML come di seguito (cambiare tema secondo le vostre esigenze).

<?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> 

in content_main.XML uso android.support.v4.widget.NestedScrollView invece di ScrollView.

utilizzare anche app:layout_behavior="@string/appbar_scrolling_view_behavior" all'interno di android.support.v4.widget.NestedScrollView come di seguito.

<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> 
+0

funziona ma non perfettamente, @ Dhawal Sodha Parmar – chanti

+0

quando faccio scorrere il mio nome della barra degli strumenti visibile nella barra di stato – chanti

+0

inserisco la mia immagine in uscita, io uso il tuo codice nel mio xml ma il mio output come sopra @ Dhawal Sodha Parmar – chanti

0

Questo è il miglior scenario di fare uso di CoordinatorLayout nella vostra app. CoordinatorLayout è un FrameLayout superpotente che ha un sacco di trucchi di animazione sulle maniche.

Libreria del progetto introduce CoordinatorLayout, un layout che fornisce un ulteriore livello di controllo sugli eventi di tocco tra vista del bambino, cosa che molti dei componenti nella progettazione libreria trarre vantaggio.

È possibile iniziare con il tutorial this e this.

+0

Ho aggiunto questa riga nella barra degli strumenti ma ancora non ricevo app in uscita: layout_scrollFlags = "scroll | enterAlways" @Aritra Roy – chanti

0

Avvolgere activity_main.xml in Layout coordinatore in modo che sia il layout principale.

<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> 
0

Potete trovare la mia soluzione sulla tua domanda da qui: Android Toolbar + Tab Layout + Drawer, Hide toolbar when scrolling and take TabLayout to the top

Questa è una solutio di lavoro, ma non è il modo migliore per attuare questa animazione. Con CoordiantorLayout puoi mettere in relazione le tue visualizzazioni e i loro comportamenti di scorrimento.

È possibile trovare maggiori informazioni da qui: https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html

quando ho tempo cercherò di postare un esempio di codice per voi.