Android仿淘宝最新向上滚动广告条

}

private View newView() {

View inflate = LayoutInflater.from(getContext()).inflate(R.layout.item_looper, null);

return inflate;

}

private void initAnimation() {

anim_out = newAnimation(0, -1);

anim_in = newAnimation(1, 0);

anim_in.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationRepeat(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

updateTipAndPlayAnimationWithCheck();

}

});

}

private Animation newAnimation(float fromYValue, float toYValue) {

Animation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,

Animation.RELATIVE_TO_SELF, fromYValue, Animation.RELATIVE_TO_SELF, toYValue);

anim.setDuration(ANIM_DURATION);

anim.setStartOffset(ANIM_DELAYED_MILLIONS);

anim.setInterpolator(new DecelerateInterpolator());

return anim;

}

private void updateTipAndPlayAnimationWithCheck() {

if (System.currentTimeMillis() - lastTimeMillis < 1000) {

return;

}

lastTimeMillis = System.currentTimeMillis();

updateTipAndPlayAnimation();

}

private void updateTipAndPlayAnimation() {

if (curTipIndex % 2 == 0) {

updateTip(tv_tip_out);

tv_tip_in.startAnimation(anim_out);

tv_tip_out.startAnimation(anim_in);

this.bringChildToFront(tv_tip_in);

} else {

updateTip(tv_tip_in);

tv_tip_out.startAnimation(anim_out);

tv_tip_in.startAnimation(anim_in);

this.bringChildToFront(tv_tip_out);

}

}

private void updateTip(View tipView) {

TextView textView = (TextView) tipView.findViewById(R.id.text_View);

LooperBean tip = getNextTip();

if (!TextUtils.isEmpty(tip.getName())) {

textView.setText(tip.getName() + TIP_PREFIX);

}

}

/**

  • 获取下一条消息

  • @return

*/

private LooperBean getNextTip() {

if (isListEmpty(tipList)) return null;

int nextPostion = curTipIndex++ % tipList.size();

if (tipList.size() == 1) {

setNowPosition(0);

} else if (nextPostion == 0) {

setNowPosition(tipList.size() - 1);

} else {

setNowPosition(nextPostion - 1);

}

AppBus.getInstance().post(new Looper(getNowPosition()));

return tipList.get(nextPostion);

}

public boolean isListEmpty(List list) {

return list == null || list.isEmpty();

}

public void setTipList(List tipList, int index) {

this.tipList = tipList;

curTipIndex = index;

updateTip(tv_tip_out);

updateTipAndPlayAnimation();

}

private void setNowPosition(int position) {

this.nowPosition = position;

}

private int getNowPosition() {

return nowPosition;

}

//获得当前滚动的位置

public int getNowTip() {

if (isListEmpty(tipList)) return -1;

return getNowPosition();

}

}

  • 滚动的文字布局
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”>

<TextView

android:id=“@+id/text_View”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_gravity=“center_vertical”

android:ellipsize=“end”

android:gravity=“center_vertical”

android:lines=“2”

android:text=“@string/app_name”

android:textColor=“#2F4F4F”

android:textSize=“16sp” />

  • 创建自动滚动的图片控件

引入图片加载框架:

compile ‘com.github.bumptech.glide:glide:3.7.0’

package tsou.cn.loopview.view;

import android.content.Context;

import android.util.AttributeSet;

import android.view.LayoutInflater;

import android.view.View;

import android.view.animation.Animation;

import android.view.animation.DecelerateInterpolator;

import android.view.animation.TranslateAnimation;

import android.widget.FrameLayout;

import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import tsou.cn.loopview.R;

import tsou.cn.loopview.bean.LooperBean;

public class LooperImageView extends FrameLayout {

private List tipList;

private int curTipIndex = 0;

private long lastTimeMillis;

private static final int ANIM_DELAYED_MILLIONS = 3 * 1000;

/**

  • 动画持续时长

*/

private static final int ANIM_DURATION = 1 * 1000;

private View tv_tip_out, tv_tip_in;

private Animation anim_out, anim_in;

private int nowPosition;

public LooperImageView(Context context) {

super(context);

initTipFrame();

initAnimation();

}

public LooperImageView(Context context, AttributeSet attrs) {

super(context, attrs);

initTipFrame();

initAnimation();

}

public LooperImageView(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

initTipFrame();

initAnimation();

}

private void initTipFrame() {

tv_tip_out = newView();

tv_tip_in = newView();

addView(tv_tip_in);

addView(tv_tip_out);

}

private View newView() {

View inflate = LayoutInflater.from(getContext()).inflate(R.layout.item_looper_image, null);

return inflate;

}

private void initAnimation() {

anim_out = newAnimation(0, -1);

anim_in = newAnimation(1, 0);

anim_in.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationRepeat(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

updateTipAndPlayAnimationWithCheck();

}

});

}

private Animation newAnimation(float fromYValue, float toYValue) {

Animation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,

Animation.RELATIVE_TO_SELF, fromYValue, Animation.RELATIVE_TO_SELF, toYValue);

anim.setDuration(ANIM_DURATION);

anim.setStartOffset(ANIM_DELAYED_MILLIONS);

anim.setInterpolator(new DecelerateInterpolator());

return anim;

}

private void updateTipAndPlayAnimationWithCheck() {

if (System.currentTimeMillis() - lastTimeMillis < 1000) {

return;

}

lastTimeMillis = System.currentTimeMillis();

updateTipAndPlayAnimation();

}

private void updateTipAndPlayAnimation() {

if (curTipIndex % 2 == 0) {

updateTip(tv_tip_out);

tv_tip_in.startAnimation(anim_out);

tv_tip_out.startAnimation(anim_in);

this.bringChildToFront(tv_tip_in);

} else {

updateTip(tv_tip_in);

tv_tip_out.startAnimation(anim_out);

tv_tip_in.startAnimation(anim_in);

this.bringChildToFront(tv_tip_out);

}

}

private void updateTip(View tipView) {

final ImageView imageView = (ImageView) tipView.findViewById(R.id.image_view);

Glide.with(tipView.getContext())

.load(tipList.get(curTipIndex % tipList.size()).getUrl())

.placeholder(R.mipmap.app_loading_pic)

.error(R.mipmap.app_loading_pic)

.into(imageView);

getNextTip();

}

/**

  • 获取下一条消息

  • @return

*/

private LooperBean getNextTip() {

if (isListEmpty(tipList)) return null;

int nextPostion = curTipIndex++ % tipList.size();

if (tipList.size() == 1) {

setNowPosition(0);

} else if (nextPostion == 0) {

setNowPosition(tipList.size() - 1);

} else {

setNowPosition(nextPostion - 1);

}

return tipList.get(nextPostion);

}

public boolean isListEmpty(List list) {

return list == null || list.isEmpty();

}

public void setTipList(List tipList, int index) {

this.tipList = tipList;

curTipIndex = index;

updateTip(tv_tip_out);

updateTipAndPlayAnimation();

}

private void setNowPosition(int position) {

this.nowPosition = position;

}

private int getNowPosition() {

return nowPosition;

}

public int getNowTip() {

if (isListEmpty(tipList)) return -1;

return getNowPosition();

}

}

  • 滚动的图片布局
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:orientation=“horizontal”>

<ImageView

android:id=“@+id/image_view”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_gravity=“center_vertical”

android:scaleType=“fitXY”

android:src=“@mipmap/app_loading_pic” />

  • 主页面布局
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“tsou.cn.loopview.MainActivity”>

<RelativeLayout

android:id=“@+id/rl_marquee_view”

android:layout_width=“match_parent”

android:layout_height=“80dp”

android:background=“#ffffff”

android:padding=“5dp”>

<ImageView

android:id=“@+id/image”

android:layout_width=“80dp”

android:layout_height=“80dp”

android:src=“@mipmap/home_message” />

<tsou.cn.loopview.view.LooperImageView

android:id=“@+id/marquee_image_view”

android:layout_width=“80dp”

android:layout_height=“match_parent”

android:layout_alignParentRight=“true”

android:layout_marginLeft=“5dp”

android:background=“#fff” />

<tsou.cn.loopview.view.LooperTextView

android:id=“@+id/marquee_text_view”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_marginLeft=“5dp”

android:layout_toLeftOf=“@id/marquee_image_view”

android:layout_toRightOf=“@id/image”

android:background=“#fff” />

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

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

img

img

img

img

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

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

最后

有任何问题,欢迎广大网友一起来交流,分享高阶Android学习视频资料和面试资料包~

偷偷说一句:群里高手如云,欢迎大家加群和大佬们一起交流讨论啊!

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**

[外链图片转存中…(img-szXP10RY-1713229432564)]

[外链图片转存中…(img-olLbKqSq-1713229432566)]

[外链图片转存中…(img-vuc8C40S-1713229432567)]

[外链图片转存中…(img-zCjR0v96-1713229432568)]

[外链图片转存中…(img-epkCMIQK-1713229432569)]

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

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

最后

有任何问题,欢迎广大网友一起来交流,分享高阶Android学习视频资料和面试资料包~

偷偷说一句:群里高手如云,欢迎大家加群和大佬们一起交流讨论啊!

[外链图片转存中…(img-HuC1nlIs-1713229432570)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值