自己手写RecycleView加深对RecycleView理解
https://blog.csdn.net/zmm911zmm/article/details/91351326
Stack getScaledTouchSlop
getScaledTouchSlop TouchSlop Stack
onInterceptTouchEvent ,onTouchEvent
Stack
getScaledTouchSlop
getScaledTouchSlop
区分手势点击和滑动的距离 界限值
RecycleView extends ViewGroup
viewList List<View>
needRelayout
heights
// view的第一行 是占内容的几行
firstRow
Adapter Recycler
AttributeSet configuration.getScaledTouchSlop
this.rowCount = adapter.getCount adapter.getHeight(i)
// 数据的高度(假设所有数据都滑动展示时,所有子ItemView高度之和)
ItemView 高度之和
sumArray(heights,0,heights.size)
setMeasuredDimension(width,height)
setAdapter
// 保存复用RecycleView的Item回收池
recycler = new Recycler(adapter.getViewTypeCount());
Recycler =
Recycler recycler = new Recycler(adapter.getViewTypeCount());
getViewTypeCount
needRelayout = true
requestLayout
removeAllViews
viewList.clear
// 摆放所有RecycleView的Item的实际高度和宽度
摆放所有RecycleView的Item的实际高度和宽度
makeAndStep top.width,bottom
viewList.add view
obtainView
int itemType = adapter.getItemViewType(row)
View recycleView = recycler.get(viewType)
adapter.onCreateViewHolder row,recyclerView,this
adapter.onBinderViewHolder row,recycleView,this
view.setTag(
R.id.tag_type_view,itemType
)
view.measure
addView(view,0)
onInterceptTouchEvent MotionEvent event
currentY = event.getRawY
// 当手指在屏幕上滑动距离大于 touchSlop 最小滑动距离时,
则继承ViewGroup的 RecyclerView 拦截事件
int diffY = currentY - event.getRawY
scrollBy(0,diffY)
// scrollY表示 第一个可见Item的左上顶点 距离屏幕的左上顶点的距离
scrollBy int x, int y2
scrollBounds (scrollY)
//2020 - 12 - 25
scrollTo scrollBy
getScaledTouchSlop() getScaledTouchSlop
Stack getScaledTouchSlop
贴上RecycleView实现中心思想的代码
RecycleView.java
RecycleView extends ViewGroup
touchSlop
viewList needRelayout firstRow RealPullRefreshView继承了一个LinearLayout
Recycler getScaledTouchSlop
touchSlop
adapter.getHeight ItemView
setMeasuredDimension(width,heightSize)
adapter.onCreateViewHolder
recycler.get
adapter.onBinderViewHolder row,recycleView,this
view.setTag
tag_type_view,itemType
addView view,0
// 当前滑动的y值
private int currentY;
touchSlop
scrollBy(0,diffY)
// 画布移动 并不影响子控件的位置
scrollBy int x
scrollBounds
// view的第一行 是占内容的几行
private int firstRow;
removeView viewList.remove(0)
scrollBounds scrollY表示
private int scrollBounds(int scrollY) {
// 上滑
if (scrollY > 0) {
} else {
// 极限值 会取零 非极限值的情况下 scroll
scrollY = Math.max(scrollY, -sumArray(heights, 0, firstRow));
}
return scrollY;
}
repositionViews
scrollBounds int scrollY表示
-sumArray(heights,0,firstRow)
scrollY表示
getFillHeight viewList.size
repositionViews() {
//
}
top = -scrollY表示
view.layout 0,top,width,bottom top = bottom
view.setTag(R.id.tag_type_view, itemType);
removeView recycler.put view
interface Adapter
scrollY heights[firstRow]
removeView
obtainView
viewList.add viewList.size,view
int firstAddRow = firstRow - 1;//
obtainView
scrollY += heights[firstRow + 1];
-heights
// 下滑移除
while (sumArray(heights, firstRow, viewList.size()) - scrollY - heights[firstRow + viewList.size() - 1] >= height) {
removeView(viewList.remove(viewList.size() - 1));
}
removeView viewList.remove
repositionViews
private void repositionViews() {
int left, top, right, bottom, i;
top = -scrollY;
i = firstRow;
for (View view : viewList) {
bottom = top + heights[i++];
view.layout(0, top, width, bottom);
top = bottom;
}
}
recycler.put view,key
view.getTag tag_type_view
Recycler
views = new Stack
recycleView.setAdapter new RecycleView.Adapter
onCreateViewHolder
getLayoutInflater.inflate
Android Scroll 滑动分析
https://www.jianshu.com/p/64a1cf4c4184
Android中窗口坐标体系和屏幕的触控事件——MotionEvent
getLocationOnScreen
系统提供了
视图坐标系
MotionEvent getX getY
com.yxc.commonlib
com.yxc.widgetlib
barchartlib
com.yxc.chartlib
gradlew processDebugManifest --stacktrace
ACTION_POINTER_DOWN ACTION_POINTER_UP
onTouchEvent MotionEvent event
//获取当前输入点的X,Y坐标(视图坐标)
int x = (int) event.getX();
int y = (int) event.getY();
Android获取坐标的方法
getY getX
MotionEvent
视图坐标 绝对坐标
实现滑动的七种方法
AndroidX该
layout方法 onLayout
//在当前的left,top,right,bottom基础上加上偏移量
layout(getLeft() + officeX, getTop() + officeY, getRight() + officeX, getBottom() + officeY);
layout(
);
offsetLeftAndRight
offsetTopAndBottom
LayoutParams
LayoutParams LayoutParams保留了一个View的布局参数,
通过改变LayoutParams来动态改变一个布局的位置参数,从而改变View位置的效果,
一个布局的位置参数,
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) getLayoutParams();
layoutParams.leftMargin = getLeft()+officeX;
layoutParams.topMargin = getTop()+officeY;
setLayoutParams(layoutParams);
RelativeLayout.LayoutParams
layoutParams属性外
ViewGroup.MarginLayoutParams layoutParams = getLayoutParams
scrollTo与scrollBy scrollTo scrollBy
比如TextView,content就是他的文本,ImageView,drawable就是对象。
getParent.scrollBy() .officeX
并不是我们想要的跟随触摸点的移动而移动,这里需要先了解一下视图移动的一些知识,
scrollBy
int officeX = rawX - lastX;
int officeY = rawY - lastY;
scrollBy(-officeX,-officeY);
scrollBy(-officeX,-officeY);
//判断Scroller是否执行完毕
mScroller.computeScrollOffset
//
getParent.scrollTo()
//getParent.scrollTo
invalidate→OnDraw→computeScroll()
startScroll开启模拟过程:
startScroll
invalidate onDraw computeScroll
ViewDragHelper
DrawerLayout SlidingPaneLayout
的基本使用方法的基础上,通过不断的练习去掌握它,我们这里就实现一个 QQ滑动侧边栏的布局,我么来看看具体怎么实现的。
ViewDragHelper
QQ滑动侧滑的布局
mViewDragHelper = ViewDragHelper.create(this,callback);
ViewDragHelper.create this,callback
拦截事件:
mViewDragHelper = ViewDragHelper.create this,callback
拦截事件:
接下来,要重写拦截事件,将事件传递给ViewDragHelper进行处理。
ViewDragHelper进行处理
2020 - 12 - 24 等比例显示StepMonthFragment Y轴坐标数据
拦截事件:
接下来,要重写拦截事件,将事件传递给ViewDragHelper进行处理。
onInterceptTouchEvent
mViewDragHelper.shouldInterceptTouchEvent
processTouchEvent
computeScroll
mViewDragHelper.continueSettling true
postInvalidateOnAnimation
tryCaptureView View child
tryCaptureView
onViewReleasedv releasedChild,xvel,yvel
if (mMainView.getLeft < 500)
mViewDragHelper.smoothSlideViewTo
smoothSlideViewTo(mMainView,0,0)
ViewCompat.postInvalidateOnAnimation DragViewGroup.this
DragViewGroup.this
定义ViewGroup的onFinishInflate()方法
定义
ViewGroup
onFinishInflate
MenuView MainView
在onFinishInflate()方法中,
按顺序将子View分别定义为MenuView和MainView,
并在onSizeChanged()方法中获得View的宽度。如果你根据View的宽度来滑动后的效果,就可以使用这个值来判断。
mMenuView = getChildAt(0)
mMainView = getChildAt(1)
onFinishInflate
getMeasuredWidth
onFinishInflate
最后通过整个ViewDragHelper来实现侧滑的代码如下:
DragViewGroup extends FrameLayout
int defStyleAttr
//XML加载组建后回调
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mMenuView = getChildAt(0);
mMainView = getChildAt(1);
}
//组件大小改变时回调
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mWidth = mMenuView.getMeasuredWidth();
}
onFinishInflate
ViewDragHelper.Callback callback =
//拖动结束后调用
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
mViewDragHelper.smoothSlideViewTo
ViewCompat.postInvalidateOnAnimation DragViewGroup.class
computeScroll mViewDragHelper.continueSettling true
onViewCaptured
onViewDragStateChanged()
draggin等状态)。idle
getAdapter
// 摆放所有RecycleView的Item的实际高度和宽度
width = mRight - mLeft;
height = mBottom - mTop;
makeAndStep obtainView getItemViewType
recycler.get itemType
recycleView.get itemType
adapter.onCreateViewHolder
adapter.onBinderViewHolder
view.setTag
scrollBounds int scrollY表示
getFillHeight firstRow ,viewList.size
sumArray heights firstRow viewList.size
sumArray( getFillHeight)
* @return 计算所有组合Item的总高度 与 RecycleView高度对比
*/
private int sumArray(int array[], int firstIndex, int count) {
}
1、首先打开命令框切换到jdk的bin目录下(每个人的bin目录不一样,大家自己找到自己相应的bin目录)
cd C:\Program Files\Java\jdk1.8.0_60\bin
2、然后输入:
keytool.exe -list -v -keystore C:\key\key.jks
后面那个路径为我的签名文件的路径
然后输入你的密令,这个密令为你当初设置的签名文件的密码
最后你就能看到相应的MD5码了
效果图: