5

Tôi đang làm cho tôi TabLayout hoạt hình bằng cách sử dụng android: animateLayoutChanges = "true" trong AppBarLayout. Nhưng khi tôi đặt TabLayout.setVisibility (View.GONE), vùng chứa cho đoạn của tôi đi lên đến ActionBar ngay lập tức trong vài phần nghìn giây. Và sau đó nó trở về cuối TabLayout và đi lên với nó tới ActionBar. Tôi giải thích điều này sau gif.Xem nhảy và chớp mắt ngay lập tức, mặc dù animateLayoutChanges = "true"

Following gif

Các nút TheoryThực hành là đằng sau những TabLayout vì một lý do nhưng khi trốn TabLayout hoạt hình bắt đầu FrameContainer chứa gậy quan điểm của tôi để dưới cùng của TabLayout.

Tôi đã ghi lại video hủy bỏ hành vi này. Trình phát video Dropbox bỏ qua một số khung hình và hoạt ảnh có vẻ thú vị. Đó là lý do tại sao, để thông báo lỗi, bạn có thể tải video trên máy tính và xem 5 và 11 giây với chất lượng cao. Video

LayoutXML của tôi:

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

Bên cạnh đó tôi đang sử dụng 23.2.1 thư viện hỗ trợ.

Làm cách nào để sửa lỗi nhấp nháy và nhảy này?

Trả lời

6

Hãy thử thêm android:animateLayoutChanges="true" để xem bạn với

app:layout_behavior="@string/appbar_scrolling_view_behavior 

do đó sẽ là DrawerLayout của bạn. Sau đó kích hoạt Loại chuyển LayoutTransition.CHANGING về nó như vậy:

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

liên quan: https://stackoverflow.com/a/22573099/1363742

0

Tôi đã lãng phí cả ngày để điều tra vấn đề này. Và tôi đã tìm thấy một giải pháp khả thi cho vấn đề này. Bây giờ tôi thay đổi mức hiển thị theo mã này

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

Nó hoạt động tốt và chế độ xem hiện không nhấp nháy. Nhưng trên androids cũ lỗi vẫn còn trình bày.

Các vấn đề liên quan