当前位置: 首页 » 产品 » 商务广告 » 正文

Android TextSwitcher如何实现文字上下翻牌效果

放大字体  缩小字体 发布日期: 2024-10-27 02:18   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:18
核心提示:tvNotice=(TextSwitcher)rootView.findViewById(R.id.tv_notice); tvNotice.setFactory(new ViewSwitcher.ViewFactory() {//这里

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="" 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="" android:fillAfter="true" android:shareInterpolator="false" android:zAdjustment="top" > <translate android:duration="1000" android:fromYDelta="0" android:toYDelta="-100%p" /> </set>

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站