使用ViewFlipper实现公告播放
来源:互联网 发布:godaddy域名push教程 编辑:程序博客网 时间:2024/06/05 16:07
效果图如下:
我设定的是3秒钟滚动一次。
废话不多说了, 上代码了:
公告滚动的动画效果
in_bottomtop.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="500" android:fromYDelta="100.0%p" android:toYDelta="0.0" /> <alpha android:duration="500" android:fromAlpha="0.0" android:toAlpha="1.0" /></set>
out_bottomtop.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="500" android:fromYDelta="0.0" android:toYDelta="-100.0%p" /> <alpha android:duration="500" android:fromAlpha="1.0" android:toAlpha="0.0" /></set>
下面是在布局中的代码
layout_main.xml
<com.zhy.autolayout.AutoLinearLayout android:id="@+id/homepage_notice_All" android:layout_width="match_parent" android:layout_height="35dp" android:layout_below="@+id/ad_view" android:layout_marginTop="@dimen/spaceing_5px" android:orientation="horizontal" android:background="@drawable/affiche_shadow" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:paddingBottom="@dimen/spaceing_20px" android:paddingLeft="@dimen/spaceing_20px" android:paddingRight="@dimen/spaceing_20px" android:paddingTop="@dimen/spaceing_20px" android:src="@mipmap/notice" /> <ViewFlipper android:id="@+id/homepage_notice_vf" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.zhy.autolayout.AutoLinearLayout>
在Java 中的代码如下
private ViewFlipper notice_vf; private TimerTask task; private void initRollNotice() { notice_vf = (ViewFlipper) findViewById(R.id.homepage_notice_vf); task = new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { moveNext(); LogUtils.i(TAG, "下一个"); } }); } }; }
initRollNotice 方法在onCreate里面调用
private int mCurrPos; private void moveNext() { setView(this.mCurrPos, this.mCurrPos + 1); this.notice_vf.setInAnimation(this, R.anim.in_bottomtop); this.notice_vf.setOutAnimation(this, R.anim.out_bottomtop); this.notice_vf.showNext(); } private void setView(int curr, int next) { View noticeView = getLayoutInflater().inflate(R.layout.notice_item, null); TextView notice_tv = (TextView) noticeView.findViewById(R.id.notice_tv); if ((curr < next) && (next > (luyaninfos.size() - 1))) { next = 0; } else if ((curr > next) && (next < 0)) { next = luyaninfos.size() - 1; } notice_tv.setText(luyaninfos.get(next).getTitle()); notice_tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Bundle bundle = new Bundle(); bundle.putString("url", luyaninfos.get(mCurrPos).getDescription()); bundle.putString("title", luyaninfos.get(mCurrPos).getTitle()); Intent intent = new Intent(MainActivity.this, LYInfoActivity.class); intent.putExtras(bundle); startActivity(intent); } }); if (notice_vf.getChildCount() > 1) { notice_vf.removeViewAt(0); } notice_vf.addView(noticeView, notice_vf.getChildCount()); mCurrPos = next; }
luyaninfos 这是一个数据集合,你可以自行修改。
这里用到了一个布局文件 R.layout.notice_item.xml 这个布局文件里面就只有一个TextView,代码如下:
<?xml version="1.0" encoding="utf-8"?><com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > <TextView android:id="@+id/notice_tv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" /></com.zhy.autolayout.AutoLinearLayout>
因为我是在获取到网络数据的时候才开始显示公告,所以开始执行定时器的代码写在了, 请求数据成功的方法里面了:
Timer timer = new Timer(); timer.schedule(task, 0, 3000);
1 0
- 使用ViewFlipper实现公告播放
- viewflipper实现幻灯片的简单播放
- ViewFlipper的使用---自动播放(轮播图)的实现以及多个view进行切换
- 自定义ViewFlipper实现带索引效果的自动播放广告栏
- UI组件之ViewFlipper实现自动播放的图片库
- 使用ViewFlipper实现图片左右滑动效果
- Android ViewFlipper的使用 实现页面滑动
- Android 实现滑动翻页---使用ViewFlipper
- 使用ViewFlipper + gridview 实现滑动翻页
- tabhost使用viewflipper实现手势滑动分页
- Android使用ViewFlipper实现Switch动画特效
- 使用ViewFlipper实现图片轮播
- 使用ViewFlipper实现屏幕滚动切换动画
- 使用ViewFlipper实现页面自动切换
- 使用viewFlipper实现轮播图,超级简单
- 使用ViewFlipper实现屏幕切换动画效果
- 使用ViewFlipper实现图片的轮播
- 使用ViewFlipper实现屏幕切换动画效果
- 【FFmpeg】FFmpeg常用基本命令
- WAV和PCM的关系和区别
- Codeforces 609C Load Balancing 【水题】
- 安卓QQ分享
- HTML+CSS
- 使用ViewFlipper实现公告播放
- 文件名浏览器兼容性(解决.net 文件名在IE和FireFox不兼容)
- 静态和动态设置EditText的属性大全
- 异常信息:RSA premaster secret error
- Linux解决Device eth0 does not seem to be present,delaying initialization错误
- 盘点2015年十大热门Android开源新项目
- 并发、并行、异步、同步、单进程、多进程、多线程...
- Hibernate 的三种状态
- java 1