本篇文章给大家分享的是有关Android开发中利用ListView实现一个渐变式的下拉刷新动画,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。主要要点listview刷新过程中主
本篇文章给大家分享的是有关Android开发中利用ListView实现一个渐变式的下拉刷新动画,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
主要要点
listview刷新过程中主要有三个步骤当前:状态为下拉刷新,当前状态为下拉刷新,当前状态为放开刷新,当前状态为正在刷新;主要思路为三个步骤分别对应三个自定义的view;即ibuRefreshFirstStepView,ibuRefreshSecondStepView,ibuRefreshThirdStepView。
效果图
ibuRefreshFirstStepView代码,例如:
private Bitmap initialBitmap; private float mCurrentProgress; private Bitmap scaledBitmap; public ibuRefreshFirstStepView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } public ibuRefreshFirstStepView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public ibuRefreshFirstStepView(Context context) { super(context); init(context); } private void init(Context context) { //这个就是那个火箭图片 initialBitmap = Bitmap.createBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.img_huojian1)); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //根据设置的宽度来计算高度 设置为符合第二阶段娃娃图片的宽高比例 setMeasuredDimension(measureWidth(widthMeasureSpec),measureWidth(widthMeasureSpec)*initialBitmap.getHeight()/initialBitmap.getWidth()); } private int measureWidth(int widMeasureSpec){ int result = 0; int size = MeasureSpec.getSize(widMeasureSpec); int mode = MeasureSpec.getMode(widMeasureSpec); if (mode == MeasureSpec.EXACTLY){ result = size; }else{ result = initialBitmap.getWidth(); if (mode == MeasureSpec.AT_MOST){ result = Math.min(result,size); } } return result; } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); // 给火箭图片进行等比例的缩放 scaledBitmap = Bitmap.createScaledBitmap(initialBitmap,89,110, false); } @Override protected void onDraw(canvas canvas) { super.onDraw(canvas); //这个方法是对画布进行缩放,从而达到椭圆形图片的缩放,第一个参数为宽度缩放比例,第二个参数为高度缩放比例,// canvas.scale(mCurrentProgress, mCurrentProgress, measuredWidth/2, measuredHeight/2); //将等比例缩放后的椭圆形画在画布上面 canvas.drawBitmap(scaledBitmap,90,dip2px(getContext(),80*mCurrentProgress),null); } public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } public void setCurrentProgress(float currentProgress){ mCurrentProgress = currentProgress; }}
--结束END--
本文标题: Android开发中利用ListView实现一个渐变式的下拉刷新动画
本文链接: https://www.lsjlt.com/news/225640.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0