25.1.0 Android支持lib正在破坏晶圆厂的行为

栏目: IOS · Android · 发布时间: 6年前

内容简介:http://stackoverflow.com/questions/41142711/25-1-0-android-support-lib-is-breaking-fab-behavior

我升级到最新的支持库版本,滚动FAB行为不起作用.当在RecyclerView上向下滚动时,它正确地向下滚动,但是当再次向上滚动时不是.它保持隐藏降级到25.0.1似乎减轻了这个问题.这里提供的代码是我使用的代码.

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:animateLayoutChanges="true"
  android:fitsSystemWindows="true"
  tools:context=".mainhost.MainActivity"
  tools:openDrawer="start">

  <android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main_coordinator_layout_root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".mainhost.MainActivity">

    <android.support.design.widget.AppBarLayout
      android:id="@+id/appbar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay">

      <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|snap">

        <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:focusableInTouchMode="true"
        app:layout_collapseMode="pin"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

    <!-- Layout for content is here. This can be a RelativeLayout  -->

    <FrameLayout
      android:id="@+id/content_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginLeft="-3dp"
      android:layout_marginRight="-3dp"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="com.globyworks.citykey.mainhost.MainActivity" />


    <android.support.design.widget.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom|end"
      android:layout_margin="@dimen/fab_margin"
      app:layout_behavior="com.globyworks.citykey.helpers.ScrollingFABBehavior"
      android:src="@drawable/drawer_new_report_white" />

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


  <android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:menu="@menu/menu_drawer">

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


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

和滚动类:

public class ScrollingFABBehavior extends FloatingActionButton.Behavior {


    public ScrollingFABBehavior(Context context, AttributeSet attrs) {
        super();
    }

    public boolean onStartNestedScroll(CoordinatorLayout parent, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {

        return true;
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
        if (dependency instanceof RecyclerView) {
            return true;
        }

        return false;
    }

    @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout,
                               FloatingActionButton child, View target, int dxConsumed,
                               int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
                             dxUnconsumed, dyUnconsumed
        );
        if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
            child.hide();
        } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
            child.show();
        }
    }
}
目前,CoordinatorLayout在查找行为以调用其onNestedScroll方法时,将视图设置为GONE.

这里的一个快速解决方法是在 end of the FAB’s hide animation 将FAB的可见性设置为INVISIBLE.

if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
    child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
        @Override
        public void onHidden(FloatingActionButton fab) {
            super.onHidden(fab);
            fab.setVisibility(View.INVISIBLE);
        }
    });
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
    child.show();
}

http://stackoverflow.com/questions/41142711/25-1-0-android-support-lib-is-breaking-fab-behavior


以上所述就是小编给大家介绍的《25.1.0 Android支持lib正在破坏晶圆厂的行为》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

深度学习框架PyTorch:入门与实践

深度学习框架PyTorch:入门与实践

陈云 / 电子工业出版社 / 2018-1 / 65

《深度学习框架PyTorch:入门与实践》从多维数组Tensor开始,循序渐进地带领读者了解PyTorch各方面的基础知识。结合基础知识和前沿研究,带领读者从零开始完成几个经典有趣的深度学习小项目,包括GAN生成动漫头像、AI滤镜、AI写诗等。《深度学习框架PyTorch:入门与实践》没有简单机械地介绍各个函数接口的使用,而是尝试分门别类、循序渐进地向读者介绍PyTorch的知识,希望读者对PyT......一起来看看 《深度学习框架PyTorch:入门与实践》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具