5

Я делаю мой TabLayout анимированный с помощью андроида: animateLayoutChanges = "истинный" в AppBarLayout. Но когда я установил TabLayout.setVisibility (View.GONE), контейнер для моего фрагмента доходит до ActionBar мгновенно в течение нескольких миллисекунд. И затем он возвращается к концу TabLayout и идет вверх по нему до ActionBar. Я объяснил это по следующему gif.Посмотреть подскакивает и мигает мгновенно, хотя animateLayoutChanges = "истинный"

Following gif

Кнопки Теория и Практика находятся за TabLayout по какой-то причине, но при скрытом TabLayout анимации начинается FrameContainer, который держит мой взгляд прилипает к нижней части TabLayout.

Я записал видео, которое демонстрирует это поведение. Dropbox видеопроигрыватель пропускает несколько кадров, и анимация кажется приятной. Вот почему, чтобы заметить ошибку, вы можете загружать видео на компьютер и смотреть 5 и 11 секунд в высоком качестве. Video

Мой 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> 

Кроме того, я использую 23.2.1 библиотеки поддержки.

Как я могу исправить это мигание и прыжки?

ответ

6

Попробуйте добавить android:animateLayoutChanges="true" на ваш взгляд, с

app:layout_behavior="@string/appbar_scrolling_view_behavior 

так, что бы ваш DrawerLayout. Затем включите Тип перехода LayoutTransition.CHANGING на него так:

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

родственный: https://stackoverflow.com/a/22573099/1363742

0

Я потратил весь день на расследование этой проблемы. И я нашел одно возможное решение этой проблемы. Теперь я изменить видимость этого кода

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); 

Он хорошо работает, и представления не мигая прямо сейчас. Но на старых андроидах ошибка все еще остается.