垂直滚动 和 水平滚动


创建一个工具类
CustomTextSwitcher

/**** 公告新闻切换** Wetchat : ljphhj* Github : https://github.com/xiaoyaomeng* Autor : lijiangping*/
public class CustomTextSwitcher extends TextSwitcher implements ViewSwitcher.ViewFactory {private Context mContext;private String[] mData;private final long DEFAULT_TIME_SWITCH_INTERVAL = 1000;//1sprivate long mTimeInterval = DEFAULT_TIME_SWITCH_INTERVAL;private int mCurrentIndex = 0;public CustomTextSwitcher(Context context, AttributeSet attrs) {super(context, attrs);this.mContext = context;setFactory(this);}public CustomTextSwitcher setInAnimation(int animationResId){Animation animation = AnimationUtils.loadAnimation(this.mContext, animationResId);setInAnimation(animation);return this;}public CustomTextSwitcher setOutAnimation(int animationResId){Animation animation = AnimationUtils.loadAnimation(this.mContext, animationResId);setOutAnimation(animation);return this;}/*** 通知/公告数据绑定* @param data* @return*/public CustomTextSwitcher bindData(String[] data){this.mData = data;return this;}public void startSwitch(long timeInterval){this.mTimeInterval = timeInterval;if (mData != null && mData.length != 0) {mSwitchHandler.sendEmptyMessage(0);}else{throw new RuntimeException("data is empty");}}/*** 工厂类中创建TextView供给TextSwitcher使用* @return*/@Overridepublic View makeView() {TextView view = new TextView(this.mContext);return view;}private Handler mSwitchHandler = new Handler(){@Overridepublic void dispatchMessage(Message msg) {super.dispatchMessage(msg);int index = mCurrentIndex % mData.length;mCurrentIndex++;setText(mData[index]);sendEmptyMessageDelayed(0, mTimeInterval);}};
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><TextViewapp:layout_constraintTop_toTopOf="parent"app:layout_constraintStart_toStartOf="parent"android:background="@drawable/ic_launcher_background"android:paddingLeft="5dp"android:paddingRight="5dp"android:paddingTop="2dp"android:paddingBottom="2dp"android:id="@+id/tvNotify1"android:layout_marginTop="50dp"android:layout_marginLeft="10dp"android:textSize="14sp"android:text="通知"android:textColor="@android:color/white"android:layout_width="40dp"android:layout_height="25dp" /><com.xxx.xxx.CustomTextSwitcherandroid:id="@+id/tvDownUpTextSwitcher"android:layout_marginLeft="5dp"app:layout_constraintTop_toTopOf="parent"app:layout_constraintBaseline_toBaselineOf="@id/tvNotify1"app:layout_constraintLeft_toRightOf="@id/tvNotify1"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextViewapp:layout_constraintTop_toBottomOf="@id/tvDownUpTextSwitcher"app:layout_constraintLeft_toLeftOf="@id/tvNotify1"android:layout_marginTop="50dp"android:paddingLeft="5dp"android:paddingRight="5dp"android:paddingTop="2dp"android:paddingBottom="2dp"android:background="@drawable/ic_launcher_background"android:id="@+id/tvNotify2"android:textSize="14sp"android:text="通知"android:textColor="@android:color/white"android:layout_width="40dp"android:layout_height="25dp" /><com.xxx.xxx.CustomTextSwitcherandroid:layout_marginLeft="5dp"app:layout_constraintBaseline_toBaselineOf="@id/tvNotify2"app:layout_constraintLeft_toRightOf="@id/tvNotify2"android:layout_marginTop="30dp"android:id="@+id/tvLeftRightTextSwitcher"android:layout_width="wrap_content"android:layout_height="wrap_content" /></androidx.constraintlayout.widget.ConstraintLayout>
/*** Wetchat : ljphhj* Github : https://github.com/xiaoyaomeng* Autor : lijiangping*/
public class MainActivity extends AppCompatActivity {CustomTextSwitcher tvDownUpTextSwitcher;CustomTextSwitcher tvLeftRightTextSwitcher;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 数据源String[] data = new String[]{"解放军于近日在东南沿海等海空域组织演习。","北京市公布了生活垃圾分类治理三年行动计划。","17日凌晨我国上空将出现一次月偏食。","中国辛鑫夺得世锦赛公开水域游泳的金牌。",};// 上下滚动tvDownUpTextSwitcher = findViewById(R.id.tvDownUpTextSwitcher);tvDownUpTextSwitcher.setInAnimation(R.anim.animation_down_up_in_animation).setOutAnimation(R.anim.animation_down_up_out_animation).bindData(data).startSwitch(2000L);// 左右滚动tvLeftRightTextSwitcher = findViewById(R.id.tvLeftRightTextSwitcher);tvLeftRightTextSwitcher.setInAnimation(R.anim.animation_left_right_in_animation).setOutAnimation(R.anim.animation_left_right_out_animation).bindData(data).startSwitch(2000L);}
}

animation_down_up_in_animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"android:shareInterpolator="false"android:zAdjustment="top"><translateandroid:duration="400"android:fromYDelta="100%"android:interpolator="@android:anim/accelerate_interpolator"android:toYDelta="0" /><alphaandroid:duration="400"android:fromAlpha="0.0"android:toAlpha="1.0" />
</set>

animation_down_up_out_animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"android:shareInterpolator="false"android:zAdjustment="bottom"><translateandroid:duration="400"android:fromYDelta="0"android:interpolator="@android:anim/accelerate_interpolator"android:toYDelta="-100%" /><alphaandroid:duration="400"android:fromAlpha="1.0"android:toAlpha="0.0" />
</set>

animation_left_right_in_animation

<set xmlns:android="http://schemas.android.com/apk/res/android"><translate android:fromXDelta="-50%p" android:toXDelta="0"android:duration="@android:integer/config_mediumAnimTime"/><alpha android:fromAlpha="0.0" android:toAlpha="1.0"android:duration="@android:integer/config_mediumAnimTime" />
</set>

animation_left_right_out_animation

<set xmlns:android="http://schemas.android.com/apk/res/android"><translate android:fromXDelta="0" android:toXDelta="50%p"android:duration="@android:integer/config_mediumAnimTime"/><alpha android:fromAlpha="1.0" android:toAlpha="0.0"android:duration="@android:integer/config_mediumAnimTime" />
</set>

Android 消息通知滚动相关推荐

  1. Android 消息通知

    Android 消息通知 文章目录 Android 消息通知 1. Toast 2. AlertDialog 2.1 普通对话框 2.2 带列表的对话框 2.3 带单选按钮的对话框 2.4 带多选按钮 ...

  2. android 通知传值,Android消息通知(notification)和PendingIntent传值

    Android支持Toast和NotificationManager两种通知方式,前者相当于一个定时关闭的对话框,后者是在状态栏上显示一条消息.Toast和Notification都可以随时取消. T ...

  3. Java中集成极光推送实现给Android提送消息通知(附代码下载)

    场景 Android中集成极光推送实现推送消息通知与根据别名指定推送附示例代码下载: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...

  4. Android中集成Jpush实现推送消息通知与根据别名指定推送附示例代码下载

    场景 经常会有后台服务向Android推送消息通知的情况. 实现 首先在Android Studio中新建一个Android应用 在Project根目录的build.gradle中配置了jcenter ...

  5. Android学习—Notification消息通知

    最近在项目中需要使用消息通知,自己把它封装成了一个方法,需要的时候方便调用, 下面对Notification类中的一些常量,字段,方法简单介绍一下: 常量: DEFAULT_ALL    使用所有默认 ...

  6. android 通知权限设置在哪,Android 打开消息通知权限

    转载自https://blog.csdn.net/rocrocflying/article/details/78333256?locationNum=8&fps=1 和 https://blo ...

  7. Android篇 --Notification(消息通知)

    Android篇 --Notification(消息通知) 消息通知(Notification)是Android系统中比较有特色的一个功能,当某个应用程序希望用户发出一些提示信息,而该应用又不在前台运 ...

  8. 「Android基于MQTT实现消息通知」

    「Android基于MQTT实现消息通知」 一.写在前面 在对接项目中IoT时,发现目前有对MQTT做了接入,这里记录一下,官方的资料比较详细,这里主要从实现细节出发:对具体的需求以及配套的技术方案进 ...

  9. Android 判断当前应用是否开启消息通知

    NotificationUtil.kt object NotificationUtil {/*** 打开手机设置页面* @param context Context*/fun setNotificat ...

  10. android通过代码设置铃声_有打扰 漏消息?那是Android手机通知设置没弄好!

    点击上方电脑爱好者关注我们 在Android系统手机的设置内容中,"通知"是最容易被我们忽略的选项.实际上,如果你每天休息时都会被各种推送提醒打扰,又或是经常错过微信.邮箱.闲鱼等 ...

最新文章

  1. Eclipse 每行 79 字符限制的提示线
  2. 零基础考信息系统项目管理师要怎么准备?
  3. Windows上使用bat实现备份一个月内的数据库数据到文件
  4. esc指令检查打印状态_Z.115 胶片自助打印设备
  5. WAV格式中常见的压缩编码
  6. 微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...
  7. 读取和写入Windows的INI文件
  8. js中的正则表达式(2)
  9. IP Multicast: MSDP RPF检测详细规则(转)
  10. LeetCode刷题——剑指offer深度优先搜索题目汇总
  11. 2019校园招聘深信服数组翻转题
  12. 在AS模拟器上访问本地电脑tomcat部署的资源报错java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8081
  13. 集成微透镜阵列的CMOS传感器分析
  14. 计算机视觉(AI)面试大全
  15. 会话层,表示层和应用层
  16. 我和掘金合作的源码共读小册报名快1000人了~
  17. vb2010中ComboBox的item用法
  18. unity2d游戏开发系列教程:二、新建工程并熟悉Unity编辑器常用功能
  19. 读《探索式软件测试》笔记(一)
  20. 二维反卷积 matlab,二维反卷积的实现(实际意义不明确)

热门文章

  1. Grid++Report报表开发工具介绍
  2. 少儿编程启蒙课程9:善用变量 拥抱变化
  3. java周总结1106
  4. 开卷有益,学习无止境
  5. U8二开之界面增加按钮处理事件
  6. PHP获取一年有多少周和每周开始和结束日期
  7. python输出数组类型_python输出数组中指定元素的所有索引示例
  8. 软件开发之大忌:想当然
  9. 用键盘控制鼠标移动的Python脚本
  10. vue图片时间轴滑动_vue 写的时间区间拖动控件