Android ViewFlipper 实现消息滚动
ViewFlipper 非常适合实现首页的消息上下滚动或是左右滚动,而且使用也是非常的方便
首先在布局中
<ViewFlipperandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/vf_msg"android:flipInterval="2500"android:inAnimation="@anim/vf_anim_in"android:outAnimation="@anim/vf_anim_out"android:layout_marginLeft="@dimen/dp_12"/>
filpinterval 是两个view之间切换的间隔 单位ms
还有一个自动开始滚动的属性
android:autoStart=“true”
inAnimation 和outAnimation 就是我们主要来实现两个view之间切换的动画
可以上下,可以左右
如下:
进入动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"android:duration="800"><translate android:fromYDelta="100%p" android:toYDelta="0"/>
</set>
出动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"android:duration="800"><translate android:fromYDelta="0" android:toYDelta="-100%p"/>
</set>
这样就是从下往上滚动的一个动画效果
从接口获取数据调用
List<String> bodyList = vfMsgBean.getBodyList();if (bodyList != null && bodyList.size() > 0){for (int i = 0; i < 3; i++) {String item = bodyList.get(i);View view = inflater.inflate(R.layout.main_rec_and_wanted_item_layout,vfJob,false);TextView textView = view.findViewById(R.id.item_tv);textView.setTextColor(getResources().getColor(R.color.red));textView.setText(item);vfMsg.addView(view);}vfMsg.startFlipping();}
这样就完成了
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
