首页 > 其他分享 >CoordinatorLayout之Behavior使用

CoordinatorLayout之Behavior使用

时间:2023-04-06 22:36:22浏览次数:49  
标签:Animator View void Behavior 使用 CoordinatorLayout animator public view



CoordinatorLayout之Behavior使用_ide


import android.animation.Animator;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.Interpolator;

/**
 * CoordinatorLayout Behavior for a quick return footer
 *
 * When a nested ScrollView is scrolled down, the quick return view will disappear.
 * When the ScrollView is scrolled back up, the quick return view will reappear.
 *
 * @author bherbst
 */
@SuppressWarnings("unused")
public class QuickReturnFooterBehavior extends CoordinatorLayout.Behavior<View> {
    private static final Interpolator INTERPOLATOR = new FastOutSlowInInterpolator();

    private int mDySinceDirectionChange;

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

    @Override
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
        return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
    }

    @Override
    public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
        if (dy > 0 && mDySinceDirectionChange < 0
                || dy < 0 && mDySinceDirectionChange > 0) {
            // We detected a direction change- cancel existing animations and reset our cumulative delta Y
            child.animate().cancel();
            mDySinceDirectionChange = 0;
        }

        mDySinceDirectionChange += dy;

        if (mDySinceDirectionChange > child.getHeight() && child.getVisibility() == View.VISIBLE) {
            hide(child);
        } else if (mDySinceDirectionChange < 0 && child.getVisibility() == View.GONE) {
            show(child);
        }
    }

    /**
     * Hide the quick return view.
     *
     * Animates hiding the view, with the view sliding down and out of the screen.
     * After the view has disappeared, its visibility will change to GONE.
     *
     * @param view The quick return view
     */
    private void hide(final View view) {
        ViewPropertyAnimator animator = view.animate()
                .translationY(view.getHeight())
                .setInterpolator(INTERPOLATOR)
                .setDuration(200);

        animator.setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {}

            @Override
            public void onAnimationEnd(Animator animator) {
                // Prevent drawing the View after it is gone
                view.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animator) {
                // Canceling a hide should show the view
                show(view);
            }

            @Override
            public void onAnimationRepeat(Animator animator) {}
        });

        animator.start();
    }

    /**
     * Show the quick return view.
     *
     * Animates showing the view, with the view sliding up from the bottom of the screen.
     * After the view has reappeared, its visibility will change to VISIBLE.
     *
     * @param view The quick return view
     */
    private void show(final View view) {
        ViewPropertyAnimator animator = view.animate()
                .translationY(0)
                .setInterpolator(INTERPOLATOR)
                .setDuration(200);

        animator.setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {
                view.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animator) {}

            @Override
            public void onAnimationCancel(Animator animator) {
                // Canceling a show should hide the view
                hide(view);
            }

            @Override
            public void onAnimationRepeat(Animator animator) {}
        });

        animator.start();
    }
}




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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:layout_behavior="com.mb.widget.QuickReturnFooterBehavior"
        android:background="@color/quickreturn_background"
        android:gravity="center"
        android:padding="16dp"
        android:text="QuickReturn Footer"
        android:textAppearance="@style/TextAppearance.AppCompat.Headline"
        android:textColor="@android:color/white" />

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




public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(this,Arrays.asList(Cheeses.sCheeseStrings)));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        
	}

}




SwipeDismissBehavior用法及实现原理


http://www.open-open.com/lib/view/open1446609550545.html



https://github.com/hugeterry/CoordinatorTabLayout

  • Test.rar (9.5 MB)
  • 下载次数: 5
  • CoordinatorLayout之Behavior使用_android_02

  • 大小: 38.7 KB
  • 查看图片附件

标签:Animator,View,void,Behavior,使用,CoordinatorLayout,animator,public,view
From: https://blog.51cto.com/u_5454003/6174221

相关文章

  • go net/http包的使用
    前言:Go语言标准库内建提供了net/http包,涵盖了HTTP客户端和服务端的具体实现。使用net/http包,我们可以很方便地编写HTTP客户端或服务端的程序。 正文:包的文档地址:https://go-zh.org/pkg/net/http net/http包使用说明:注册路由http.HandleFunc("/index",getHandle)  ......
  • 使用nvm管理(切换)node版本
    使用nvm切换node版本1.完全删除之前的node及npm(清理干净Node:应用程序,缓存的文件,环境变量)2.使用管理员身份安装nvm,下载如下3.安装完nvm之后找到nvm下载路径对应的文件4.使用管理员身份打开cmd,nvminstallxxx(node的版本),两个版本都执行一次下载命令5.执行完4之后,nvm路径下......
  • 关于ListView中使用GestureDetector冲突的解决办法
    在做OnGestureListener手势滑动界面的时候,会遇到这样的问题,就是当界面中含有ListView的时候,OnGestureListener的界面滑动就被ListView拦截并消费掉了。为了解决这个问题需要重写ListView的OnTouchListener接口:ListViewlistView=(ListView)findViewById(R......
  • Spring Cache使用方式——不用默认,使用redis进行缓存
    在SpringBoot项目中使用SpringCache的操作步骤(使用redis缓存技术)1、导入Maven坐标spring-boot-starter-data-redis、sping-boot-starter-cache2、配置application.ymlspring:cache:redis:time-to-live:1800000#设置缓存......
  • 08、foamSearch使用
    我们可以使用openfoam自带的foamSearch工具进行搜索在某个文件夹内搜索文件的某个内容foamSearch$FOAM_TUTORIALSfvSchemes"divSchemes/div(phi,U)"输出结果div(phi,U)boundedGausslimitedLinear0.2;div(phi,U)boundedGausslimitedLinearV1;div(phi,U......
  • foreach/增强for循环 中 使用iterator.remove();
    Set<String>set=newHashSet<>();set.add("a");set.add("b");Iterator<String>iterator=set.iterator();for(Stringstring:set){iterator.next();iterator.remove();} Excep......
  • 【Azure 应用服务】使用Docker Compose创建App Service遇见"Linux Version is too lo
    问题描述使用DockerCompose方式合并多个镜像(Images)文件,然后部署到AppService中,结果失败。报错LinuxVersion太长,不能超过4000个字符。错误消息:{"code":"DeploymentFailed","message":"Atleastoneresourcedeploymentoperationfailed.Pleaselistdeploymentoper......
  • Spring Cache使用
    packagecom.itheima.controller;importcom.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;importcom.itheima.entity.User;importcom.itheima.service.UserService;importlombok.extern.slf4j.Slf4j;importorg.springframework.beans.factory.a......
  • 使用open live writer客户端写博客(亲测有效)
    博客都开了这么久了,才开始将资料上传,但是每次都要登录网页确实很麻烦,所以就用openlivewriter,使用起来真的是挺方便的,所以将我在安装配置时,发现的问题汇总起来以便日后再次碰到忘记怎么处理了,哈哈,我记性不好 一:安装                              ......
  • 使用TableLayout应该注意的地方
    4.0之后推荐使用GridLayout代替TableLayout详情见:浅谈android4.0开发之GridLayout布局TableLayout和我们平时在网页上见到的Table有所不同,TableLayout没有边框的,它是由多个TableRow对象组成,每个TableRow可以有0个或多个单元格,每个单元格就是一个View。......