当前位置: 首页 > news >正文

网站内容建设与管理wordpress 开源模板

网站内容建设与管理,wordpress 开源模板,济南seo整站外包,做养生产品哪个网站好效果图#xff1a; 前言#xff1a; 看了网上很多惯性滚动方案#xff0c;都是通过Scroller 配合 computeScroll实现的#xff0c;但在实际开发中可能有一些场景不合适#xff0c;比如协调布局#xff0c;内部子View有特别复杂的联动效果#xff0c;需要通过偏移来配合…效果图 前言 看了网上很多惯性滚动方案都是通过Scroller 配合 computeScroll实现的但在实际开发中可能有一些场景不合适比如协调布局内部子View有特别复杂的联动效果需要通过偏移来配合。我通过VelocityTracker速度跟踪器实现了相同的效果感觉还行欢迎指正虚拟机有延迟真机效果更好。 1. 布局文件 activity_main.xml ?xml version1.0 encodingutf-8? FrameLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivitycom.example.flingscrollview.LinerScrollViewandroid:idid/mScrollViewandroid:orientationverticalandroid:layout_heightmatch_parentandroid:layout_widthmatch_parent//FrameLayout 2. 演示View package com.example.flingscrollview;import android.content.Context; import android.graphics.Color; import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; import android.view.Gravity; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView;import androidx.annotation.Nullable;public class LinerScrollView extends LinearLayout {final Handler mHandler;private final int mTouchSlop; // 移动的距离大于这个像素值的时候会认为是在滑动private final int mMinimumVelocity; // 最小的速度private final int mMaximumVelocity; // 最大的速度private VelocityTracker mVelocityTracker; // 速度跟踪器private int mScrollPointerId; // 当前最新放在屏幕伤的手指private int mLastTouchX; // 上一次触摸的X坐标private int mLastTouchY; // 上一次触摸的Y坐标private int mInitialTouchX; // 初始化触摸的X坐标private int mInitialTouchY; // 初始化触摸的Y坐标public final int SCROLL_STATE_IDLE -1; // 没有滚动public final int SCROLL_STATE_DRAGGING 1; // 被手指拖动情况下滚动public final int SCROLL_STATE_SETTLING 2; // 没有被手指拖动情况下惯性滚动private int mScrollState SCROLL_STATE_IDLE; // 滚动状态// 在测试过程中通过速度正负值判断方向方向有概率不准确// 所以我在onTouchEvent里自己处理private boolean direction true; // true向上 false向下private FlingTask flingTask; // 惯性任务public LinerScrollView(Context context, Nullable AttributeSet attrs) {super(context, attrs);mHandler new Handler(Looper.getMainLooper());// 一些系统的预定义值:ViewConfiguration configuration ViewConfiguration.get(getContext());mTouchSlop configuration.getScaledTouchSlop();mMinimumVelocity configuration.getScaledMinimumFlingVelocity();mMaximumVelocity configuration.getScaledMaximumFlingVelocity();initView();}/*** 初始化视图*/private void initView() {for (int i 0; i 50; i) {TextView textView new TextView(getContext());ViewGroup.LayoutParams params new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 350);textView.setLayoutParams(params);textView.setText(index i);textView.setTextColor(Color.BLACK);textView.setTextSize(30);textView.setBackgroundColor(Color.CYAN);textView.setGravity(Gravity.CENTER_VERTICAL);addView(textView);}}boolean notUp false; // 是否 不能再向上滑了boolean notDown false; // 是否 不能再向下滑了int listMaxOffsetY 0; // 列表最大滑动Y值/*** 滚动列表* param offsetY 偏移Y值*/private void translationViewY(int offsetY) {if (listMaxOffsetY 0) {listMaxOffsetY (350 * 50) - getHeight();}if (mScrollState SCROLL_STATE_DRAGGING) {if (direction) { // 向上滑动if (Math.abs(getChildAt((getChildCount() - 1)).getTranslationY()) listMaxOffsetY) {notUp false;}} else { // 向下滑动if (getChildAt(0).getTranslationY() 0) {notDown false;}}}for (int i 0; i getChildCount(); i) {View childView getChildAt(i);int yv (int) (childView.getTranslationY() offsetY);if (direction) { // 向上滑动notDown false;if (!notUp) {if (Math.abs(yv) listMaxOffsetY) {notUp true;}}if (!notUp) childView.setTranslationY(yv);} else { // 向下滑动notUp false;if (!notDown) {if (yv 0) {notDown true;}}if (!notDown) childView.setTranslationY(yv);}}}/*** 惯性任务* param velocityX X轴速度* param velocityY Y轴速度* return*/private boolean fling(int velocityX, int velocityY) {if (Math.abs(velocityY) mMinimumVelocity) {flingTask new FlingTask(Math.abs(velocityY), mHandler, new FlingTask.FlingTaskCallback() {Overridepublic void executeTask(int dy) {if (direction) { // 向上滑动translationViewY(-dy);} else { // 向下滑动translationViewY(dy);}}Overridepublic void stopTask() {setScrollState(SCROLL_STATE_IDLE);}});flingTask.run();setScrollState(SCROLL_STATE_SETTLING);return true;}return false;}/*** 停止惯性滚动任务*/private void stopFling() {if (mScrollState SCROLL_STATE_SETTLING) {if (flingTask ! null) {flingTask.stopTask();setScrollState(SCROLL_STATE_IDLE);}}}Overridepublic boolean onTouchEvent(MotionEvent event) {super.onTouchEvent(event);boolean eventAddedToVelocityTracker false;// 获取一个新的VelocityTracker对象来观察滑动的速度if (mVelocityTracker null) {mVelocityTracker VelocityTracker.obtain();}mVelocityTracker.addMovement(event);// 返回正在执行的操作不包含触摸点索引信息。即事件类型如MotionEvent.ACTION_DOWNfinal int action event.getActionMasked();int actionIndex event.getActionIndex();// Action的索引// 复制事件信息创建一个新的事件防止被污染final MotionEvent copyEv MotionEvent.obtain(event);switch (action) {case MotionEvent.ACTION_DOWN: { // 手指按下stopFling();// 特定触摸点相关联的触摸点id,获取第一个触摸点的idmScrollPointerId event.getPointerId(0);// 记录down事件的X、Y坐标mInitialTouchX mLastTouchX (int) (event.getX() 0.5f);mInitialTouchY mLastTouchY (int) (event.getY() 0.5f);}break;case MotionEvent.ACTION_POINTER_DOWN: { // 多个手指按下// 更新mScrollPointerId,表示只会响应最近按下的手势事件mScrollPointerId event.getPointerId(actionIndex);// 更新最近的手势坐标mInitialTouchX mLastTouchX (int) (event.getX() 0.5f);mInitialTouchY mLastTouchY (int) (event.getY() 0.5f);}break;case MotionEvent.ACTION_MOVE: { // 手指移动setScrollState(SCROLL_STATE_DRAGGING);// 根据mScrollPointerId获取触摸点下标final int index event.findPointerIndex(mScrollPointerId);// 根据move事件产生的xy来计算偏移量dxdyfinal int x (int) (event.getX() 0.5f);final int y (int) (event.getY() 0.5f);int dx Math.abs(mLastTouchX - x);int dy Math.abs(mLastTouchY - y);// 在手指拖动状态下滑动if (mScrollState SCROLL_STATE_DRAGGING) {if (mLastTouchY - y 0.5f) {direction true;// Log.d(TAG, 向上);translationViewY(-dy);} else if (y - mLastTouchY 0.5f) {direction false;// Log.d(TAG, 向下);translationViewY(dy);}}mLastTouchX x;mLastTouchY y;}break;case MotionEvent.ACTION_POINTER_UP: { // 多个手指离开// 选择一个新的触摸点来处理结局重新处理坐标onPointerUp(event);}break;case MotionEvent.ACTION_UP: { // 手指离开滑动事件结束mVelocityTracker.addMovement(copyEv);eventAddedToVelocityTracker true;// 计算滑动速度// mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);// 最后一次 X/Y 轴的滑动速度final float xVel -mVelocityTracker.getXVelocity(mScrollPointerId);final float yVel -mVelocityTracker.getYVelocity(mScrollPointerId);if (!((xVel ! 0 || yVel ! 0) fling((int) xVel, (int) yVel))) {setScrollState(SCROLL_STATE_IDLE); // 设置滑动状态}resetScroll(); // 重置滑动}break;case MotionEvent.ACTION_CANCEL: { //手势取消释放各种资源cancelScroll(); // 退出滑动}break;}if (!eventAddedToVelocityTracker) {// 回收滑动事件方便重用调用此方法你不能再接触事件mVelocityTracker.addMovement(copyEv);}// 回收滑动事件方便重用copyEv.recycle();return true;}/*** 有新手指触摸屏幕更新初始坐标* param e*/private void onPointerUp(MotionEvent e) {final int actionIndex e.getActionIndex();if (e.getPointerId(actionIndex) mScrollPointerId) {// Pick a new pointer to pick up the slack.final int newIndex actionIndex 0 ? 1 : 0;mScrollPointerId e.getPointerId(newIndex);mInitialTouchX mLastTouchX (int) (e.getX(newIndex) 0.5f);mInitialTouchY mLastTouchY (int) (e.getY(newIndex) 0.5f);}}/*** 手指离开屏幕*/private void cancelScroll() {resetScroll();setScrollState(SCROLL_STATE_IDLE);}/*** 重置速度*/private void resetScroll() {if (mVelocityTracker ! null) {mVelocityTracker.clear();}}/*** 更新 滚动状态* param state*/private void setScrollState(int state) {if (state mScrollState) {return;}mScrollState state;}}3. 惯性滚动任务类核心类 package com.example.flingscrollview;import android.os.Handler; import android.util.Log;class FlingTask implements Runnable {private Handler mHandler;private int velocityY 0;private int originalVelocityY 0;private FlingTaskCallback flingTaskCallback;public FlingTask(int velocityY, Handler handler, FlingTaskCallback callback) {this.velocityY velocityY;this.mHandler handler;this.originalVelocityY velocityY;this.flingTaskCallback callback;}boolean initSlide false; // 初始化滑动int average 0; // 平均速度int tempAverage 1;boolean startSmooth false; // 开始递减速度平滑处理int sameCount 0; // 值相同次数// 这里控制平均每段滑动的速度private int getAverageDistance(int velocityY) {int t velocityY;if (t 470) {t / 21;}// divide by zeroif (t 0) return 0;int v Math.abs(velocityY / t);if (v 21) {t / 21;if (t 20) {t / 5;}}return t;}Overridepublic void run() {// 速度完全消耗完才结束任务和view滚动结束不冲突// 这个判断是为了扩展将没消耗完的速度转给指定的滚动view// if (velocityY 0) {// 只要view滚动结束立刻结束任务if (tempAverage 0 velocityY 0) {if (!initSlide) {average getAverageDistance(velocityY);initSlide true;}float progress (float) velocityY / originalVelocityY;float newProgress 0f;if (average 300) {newProgress getInterpolation(progress);} else {newProgress getInterpolation02(progress);}int prTemp tempAverage;if (!startSmooth) tempAverage (int) (average * newProgress);// 递减速度平滑处理if (prTemp tempAverage) {sameCount;if (sameCount 1 tempAverage 0) { // 这个值越大最后衰减停止时越生硬0 - 30tempAverage--;sameCount 0;startSmooth true;}}flingTaskCallback.executeTask(tempAverage);velocityY - tempAverage;// 这里这样写是为了扩展将没消耗完的速度转给其他滚动列表// 判断语句需要改成 if (velocityY 0)if (tempAverage 0) { // view滚动停止时// 如果速度没有消耗完继续消耗velocityY - average;}// Log.d(TAG, tempAverage tempAverage --- velocityY velocityY --- originalVelocityY originalVelocityY);mHandler.post(this);} else {flingTaskCallback.stopTask();stopTask();}}public void stopTask() {mHandler.removeCallbacks(this);initSlide false;}// 从加速度到逐步衰减AccelerateDecelerateInterpolator插值器 核心源码public float getInterpolation(float input) {return (float) (Math.cos((input 1) * Math.PI) / 2.0f) 0.5f;}// 速度逐步衰减DecelerateInterpolator插值器 核心源码public float getInterpolation02(float input) {return (float) (1.0f - (1.0f - input) * (1.0f - input));}interface FlingTaskCallback {void executeTask(int dy);void stopTask();} }4. Activity package com.example.flingscrollview;import androidx.appcompat.app.AppCompatActivity;import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;public class MainActivity extends AppCompatActivity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}
http://www.zqtcl.cn/news/698850/

相关文章:

  • 现在的网站内容区域做多宽俄文网站开发翻译
  • 上海闵行建设局官方网站做电影网站的流程
  • 怎样做水族馆网站wordpress第三方订阅地址
  • 东莞做网站注意事项如何查网站的百度快照
  • 做资源网站需要什么郑州哪有做网站的公司
  • 不属于网站架构开发一个游戏软件多少钱
  • 电子商务网站建设 市场分析广州有哪些做网站专业的公司
  • 广州网站建设南宁厦门城健建设有限公司网站
  • 课程网站开发的研究现状网页设计制作音乐网站
  • 建设工程法律网站网站美工做专题尺寸多少?
  • 甘肃制作网站godaddy wordpress空间
  • 做淘宝客网站要多少钱心理网站模板
  • 建设手机网站经验分享网站外链建设实例
  • 乔拓云网站注册外贸个人网站
  • 个人怎么做动漫短视频网站建设银行银监会官方网站
  • 长沙网站seo技术厂家山东济宁网站建设设计
  • 外贸网站制作有哪些做体育的网站
  • 广州哪里有做网站推广最牛的网站建
  • 建设网站用户名是什么原因世界500强企业排名2020
  • 创建网站要找谁手机网站后台源码
  • canvas网站源码网站静态和动态区别
  • 网站建设需要了解哪些方面数据分析工具
  • 求个网站没封的2021网站建设初步课程介绍
  • 沈阳网站前端网站建栏目建那些
  • 经典网站案例江苏省建设厅官网
  • 公司建设网站需要多少钱重庆房产网站建设
  • 鹤岗市建设局网站可信网站认证有用吗
  • 网站注册的账号怎么注销如何百度推广
  • 用wordpress制作网站模板阿里云网站建设合作
  • 金华建设公司网站宝武马钢集团公司招聘网站