Android 下拉式抽屉折叠动画(1),2024年最新阿里 p7 面经

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注Android)
img

正文

//                Log.e(“dy”,“++++++++++++++++++++++++++++”+dy);

int scrollY = getScrollY();

//mDownY - moveY>0上滑

if (scrollY + dy > 0) {

scrollBy(0, dy);

if (scrollY + dy > getHeight_top()) {

scrollTo(0, getHeight_top());

}

}

downX = moveX;

downY = moveY;

break;

case MotionEvent.ACTION_UP:

//                Log.e(“heigth_top”, “+++++++++++++++++” + height_top);

//                Log.e(“scrollY”, “+++++++++++++++++” + getScrollY());

if (opened) {

open(!(getScrollY() > ambit_scroll || getScrollY() > getHeight_top() / 3));

} else {

open(getScrollY() < getHeight_top() - ambit_scroll || getScrollY() < getHeight_top() * 2 / 3);

}

break;

}

// 消费掉

return true;

}

/**

* 开闭抽屉

*

* @param open

*/

public void open(boolean open) {

setY_opened();

this.opened = open;

//打开

if (open) {

//            Log.e(“打开”, “+++++++++++++++++++++++++++++”);

int startX = getScrollX();// 起始的坐标X

int startY = getScrollY();// 起始的坐标Y

int endX = 0;

int endY = 0;

int dx = endX - startX;// 增量X

int dy = endY - startY;// 增量Y

// 1px = 10

int duration = Math.abs(dy) * 10;

if (duration > duration_max) {

duration = duration_max;

}

mScroller.startScroll(startX, startY, dx, dy, duration);

} else {

Log.e(“关闭”, “+++++++++++++++++++++++++++++” + getScrollY());

int startX = getScrollX();// 起始的坐标X

int startY = getScrollY();// 起始的坐标Y

int endX = 0;

int endY = getHeight_top();

int dx = endX - startX;// 增量X

int dy = endY - startY;// 增量Y

// 1px = 10

int duration = Math.abs(dy) * 10;

if (duration > duration_max) {

duration = duration_max;

}

// 模拟数据变化

mScroller.startScroll(startX, startY, dx, dy, duration);

}

invalidate();// 触发ui绘制 --> draw() --> dispatchDraw()–> drawChild -->

}

@Override

public void computeScroll() {

if (mScroller.computeScrollOffset()) {// 如果正在计算的过程中

// 更新滚动的位置

scrollTo(0, mScroller.getCurrY());

invalidate();

}

}

@Override

protected void onScrollChanged(int l, int t, int oldl, int oldt) {

super.onScrollChanged(l, t, oldl, oldt);

//        Log.e(“y_now”, ScreenUtils.getViewScreenLocation(view_bottom)[1] + “++++++++++++++++++++++”);

//

//        Log.e(“y_closed”, y_opened - height_top + “++++++++++++++++++++++”);

if (onSwitchListener != null) {

onSwitchListener.onSwitching(t - oldt < 0 ? true : false,

getY_now(), getY_opened(), getY_opened() - getHeight_top());

if (getY_now() == getY_opened()) {

//                Log.e(“true”, “++++++++++++++++++++++++”);

onSwitchListener.onSwitched(true);

}

if (getY_now() == getY_opened() - getHeight_top()) {

//                Log.e(“false”, “++++++++++++++++++++++++”);

onSwitchListener.onSwitched(false);

}

}

}

public boolean isOpened() {

return opened;

}

public int getDuration_max() {

return duration_max;

}

/**

* 设置松手后 开闭最长过渡时间

*

* @param duration_max

*/

public void setDuration_max(int duration_max) {

this.duration_max = duration_max;

}

public View getView_top() {

return view_top;

}

public View getView_bottom() {

return view_bottom;

}

public int getHeight_top() {

return view_top.getMeasuredHeight();

}

/**

* 获取 * y_opened:抽屉打开时view_bootom的top y

*/

private void setY_opened(){

if (y_opened<0){

y_opened=getViewScreenLocation(view_bottom)[1];

Log.e(“y _open”,y_opened+“++++++++++++++++++++”);

}

}

/**

* y_opened:抽屉打开时view_bootom的top y

*

* @return

*/

public int getY_opened() {

if (y_opened<0){

Log.e(“还未计算出来”,“+++++++++++++++++++++++++++++++++++”);

return 0;

}

return y_opened;

}

/**

* y_now:抽屉实时view_bootom的top y

*

* @return

*/

public int getY_now() {

return getViewScreenLocation(view_bottom)[1];

}

public int getAmbit_scroll() {

return ambit_scroll;

}

/**

* 修改滑动界限 值,值越大  开闭越难  单位ms

*

* @param ambit_scroll <height_top

*/

public void setAmbit_scroll(int ambit_scroll) {

this.ambit_scroll = ambit_scroll;

}

/**

* 计算指定的 View 在屏幕中的坐标。

*/

public  int[] getViewScreenLocation(View view) {

int[] location = new int[2];

// 获取控件在屏幕中的位置,返回的数组分别为控件左顶点的 x、y 的值

view.getLocationOnScreen(location);

return location;

}

public interface OnSwitchListener {

/*

滑动中

y_now:实时view_bottom的top y, y_opened:抽屉打开时view_bootom的top y,y_closed:抽屉关闭时view_bottom的top y  top y:在屏幕中的top y坐标

*/

public void onSwitching(boolean isToOpen, int y_now, int y_opened, int y_closed);

/*

滑动停止,状态是否开闭

*/

public void onSwitched(boolean opened);

}

public void setOnSwitchListener(OnSwitchListener onSwitchListener) {

this.onSwitchListener = onSwitchListener;

}

}

2、activity实现代码,可打开可关闭抽屉动画,可监听动画距离——渐变效果

=======================================

final TextView tv_middle = (TextView) findViewById(R.id.tv_middle);

final SlidingMenuVertical slidingMenuVertical = ((SlidingMenuVertical) findViewById(R.id.slidingMenu));

slidingMenuVertical.setDuration_max(2300);

slidingMenuVertical.setAmbit_scroll(100);

slidingMenuVertical.setOnSwitchListener(new SlidingMenuVertical.OnSwitchListener() {

/*

滑动中

y_now:实时view_bottom的top y, y_opened:抽屉打开时view_bootom的top y,y_closed:抽屉关闭时view_bottom的top y top y:在屏幕中的top y坐标

*/

@Override

public void onSwitching(boolean isToOpen, int y_now, int y_opened, int y_closed) {

tv_middle.setBackgroundColor(Color.argb((int) (1.0f * (y_opened - y_now) / (y_opened - y_closed) * 255),

Color.red(0xff3F51B5), Color.green(0xff3F51B5), Color.blue(0xff3F51B5)));

tv_middle.setTextColor(Color.argb((int) (1.0f * (y_opened - y_now) / (y_opened - y_closed) * 255),

Color.red(0xffffffff), Color.green(0xffffffff), Color.blue(0xffffffff)));

}

@Override

public void onSwitched(boolean opened) {

if (opened) {

tv_middle.setBackgroundColor(0xffffffff);

tv_middle.setTextColor(0xff454545);

}

}

});

findViewById(R.id.tv_switch).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

slidingMenuVertical.open(!slidingMenuVertical.isOpened());

}

});

3、layout.xml文件。

===============

说明:SlidingMenuVertical里面第一个item就是抽屉内容——可以是view,可以是ViewGroup,第二个item就是抽屉下面的内容,第二个item里面ScrollView外部view可开关抽屉内容

<com.tianxin.choutis.SlidingMenuVertical

android:id=“@+id/myct”

android:layout_below=“@+id/kgte”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<TextView

android:id=“@+id/myte”

android:layout_width=“match_parent”

android:layout_height=“150dp”

android:background=“@color/colorAccent”

android:text=“Hello World!” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”>

<TextView

android:id=“@+id/tv_middle”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:textColor=“#454545” />

<ScrollView

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“#e6e6e6”

android:overScrollMode=“never”

android:scrollbars=“vertical”>

最后

分享一份工作1到5年以上的Android程序员架构进阶学习路线体系,希望能对那些还在从事Android开发却还不知道如何去提升自己的,还处于迷茫的朋友!

  • 阿里P7级Android架构师技术脑图;查漏补缺,体系化深入学习提升

  • **全套体系化高级架构视频;**七大主流技术模块,视频+源码+笔记

有任何问题,欢迎广大网友一起来交流

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注Android)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

ight=“match_parent”

android:background=“#e6e6e6”

android:overScrollMode=“never”

android:scrollbars=“vertical”>

最后

分享一份工作1到5年以上的Android程序员架构进阶学习路线体系,希望能对那些还在从事Android开发却还不知道如何去提升自己的,还处于迷茫的朋友!

  • 阿里P7级Android架构师技术脑图;查漏补缺,体系化深入学习提升

[外链图片转存中…(img-25XQJhL0-1713664161454)]

  • **全套体系化高级架构视频;**七大主流技术模块,视频+源码+笔记

[外链图片转存中…(img-tY7A56CA-1713664161454)]

有任何问题,欢迎广大网友一起来交流

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注Android)
[外链图片转存中…(img-0uJQAb2c-1713664161455)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 16
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值