温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在Android中利用TextSwitcher实现一个文字上下翻牌效果

发布时间:2020-12-05 16:02:30 来源:亿速云 阅读:280 作者:Leah 栏目:移动开发

今天就跟大家聊聊有关如何在Android中利用TextSwitcher实现一个文字上下翻牌效果,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

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

<&#63;xml version="1.0" encoding="utf-8"&#63;> 
<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

<&#63;xml version="1.0" encoding="utf-8"&#63;> 
<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中利用TextSwitcher实现一个文字上下翻牌效果有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI