欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

Android TextSwitcher实现文字上下翻牌效果(铜板街)

时间:2021-04-26 11:06:00|栏目:Android代码|点击:

tvNotice = (TextSwitcher)rootView.findViewById(R.id.tv_notice); 
 tvNotice.setFactory(new ViewSwitcher.ViewFactory() { 
  //这里 用来创建内部的视图,这里创建TextView,用来显示文字 
   public View makeView() { 
    TextView tv =new TextView(getContext()); 
    //设置文字大小 
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX,getResources().getDimension(R.dimen.group_notice_font_size)); 
    //设置文字 颜色 
    tv.setTextColor(getResources().getColor(R.color.font_333333)); 
    return tv; 
   } 
  });  

然后自己可用timer或者Thread去控制轮播,轮播中控制tvNotice的代码如下

// 设置切入动画 
tvNotice.setInAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.slide_in_bottom)); 
// 设置切出动画 
tvNotice.setOutAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.slide_out_up)); 
//items是一个字符串列表,index就是动态的要显示的items中的索引 
tvNotice.setText(itmes.get(index).getTitle()); 

slide_in_bottom.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
 android:fillAfter="true" 
 android:shareInterpolator="false" android:zAdjustment="top" 
 > 
 <translate 
  android:duration="1000" 
  android:fromYDelta="100%p" 
  android:toYDelta="0" /> 
</set> 

slide_out_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
 android:fillAfter="true" 
 android:shareInterpolator="false" android:zAdjustment="top" 
 > 
 <translate 
  android:duration="1000" 
  android:fromYDelta="0" 
  android:toYDelta="-100%p" /> 
</set> 

上一篇:Android使用AsyncTask下载图片并显示进度条功能

栏    目:Android代码

下一篇:Android7.0 MTK设置默认桌面

本文标题:Android TextSwitcher实现文字上下翻牌效果(铜板街)

本文地址:http://www.codeinn.net/misctech/109430.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有