5

Robię mój TabLayout animowane za pomocą androida: animateLayoutChanges = "true" w AppBarLayout. Ale kiedy ustawiam TabLayout.setVisibility (View.GONE), kontener dla mojego fragmentu przechodzi na ActionBar natychmiast na kilka milisekund. A następnie powraca do końca TabLayout i idzie w górę z nim do ActionBar. Wyjaśniłem to naśladując gif.Zobacz skoki i miga od razu, choć animateLayoutChanges = "true"

Following gif

Przyciski Teoria i Practice są za TabLayout z jakiegoś powodu, ale gdy ukrywanie animacji TabLayout zaczyna FrameContainer że posiada moim zdaniem kije do dołu TabLayout.

Nagrałem film, który demonstruje to zachowanie. Odtwarzacz wideo Dropbox pomija niektóre klatki, a animacja wydaje się miła. To dlatego, aby zauważyć błąd, można załadować wideo na komputerze i oglądać 5 i 11 sekund w wysokiej jakości. Video

Moja LayoutXML:

<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:orientation="vertical"> 

<SurfaceView 
    android:layout_width="0px" 
    android:layout_height="0px"/> 

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

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 


    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:visibility="gone" 
     app:tabGravity="fill" 
     app:tabIndicatorColor="@android:color/white" 
     app:tabMode="fixed"/> 

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

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <!-- 
     This FrameLayout holds my fragments. 
    --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/outer_background"> 

     <ProgressBar 
      android:id="@+id/main_load_progress" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:indeterminate="true"/> 
    </FrameLayout> 

    <include 
     android:id="@+id/left_drawer_full" 
     layout="@layout/navigation_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start"/> 

</android.support.v4.widget.DrawerLayout> 

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

Ponadto używam 23.2.1 biblioteki obsługi.

Jak mogę naprawić to miganie i skoki?

Odpowiedz

6

spróbuj dodać android:animateLayoutChanges="true" do widoku z

app:layout_behavior="@string/appbar_scrolling_view_behavior 

więc byłby to DrawerLayout. Następnie włączyć Transition Type LayoutTransition.CHANGING na nim tak:

ViewGroup layout = (ViewGroup) findViewById(R.id. drawer_layout); 
LayoutTransition layoutTransition = layout.getLayoutTransition(); 
layoutTransition.enableTransitionType(LayoutTransition.CHANGING); 

pokrewne: https://stackoverflow.com/a/22573099/1363742

0

Zmarnowałem cały dzień, aby zbadać ten problem. I znalazłem jedno możliwe rozwiązanie tego problemu. Teraz mogę zmienić widoczność przez ten kod

mTabLayout.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      switch (newMode) { 
       case MODE_CONTENTS: 
        mTabLayout.setVisibility(mContents.isTheoryAvailable() ? View.VISIBLE : View.GONE); 
        break; 
       default: 
        findViewById(R.id.content_frame).setVisibility(View.INVISIBLE); 
        mTabLayout.setVisibility(View.GONE); 
        findViewById(R.id.content_frame).setVisibility(View.VISIBLE); 
      } 
     } 
    }, 200); 

To działa dobrze i widoki nie migają teraz. Ale na starych androidach błąd wciąż jest obecny.

Powiązane problemy