类似于淘宝中的淘宝头条

ViewFlipper
布局文件:

<LinearLayout                android:id="@+id/ll_vf"                android:layout_width="match_parent"                android:layout_height="60dp"                android:layout_marginBottom="25dp"                android:background="@color/white"                android:gravity="center"                android:paddingLeft="@dimen/content_space_h"                android:paddingRight="@dimen/content_space_h">                <ViewFlipper                    android:id="@+id/vf_notice"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"/>            LinearLayout>

java代码:

    @ViewInject(R.id.ll_vf)    private LinearLayout ll_vf;    @ViewInject(R.id.vf_notice)    private ViewFlipper vf_notice;    private int mCurrPos;    private int mCurrPos;    private Timer timer;    private TimerTask task;    // 其中data为传入的数据    private void initRollNotice(final List.PrizeList.Rows> data) {        task = new TimerTask() {            @Override            public void run() {                runOnUiThread(new Runnable() {                    @Override                    public void run() {                        moveNext(data);                    }                });            }        };        timer = new Timer();        timer.schedule(task, 0, 5000);    }    private void moveNext(List.PrizeList.Rows> data) {        setView(data, this.mCurrPos, this.mCurrPos + 1);        this.vf_notice.setInAnimation(this, R.anim.in_bottom);        this.vf_notice.setOutAnimation(this, R.anim.out_top);        this.vf_notice.showNext();    }    private void setView(List.PrizeList.Rows> data, int curr, int next) {        View noticeView = getLayoutInflater().inflate(R.layout.item_draw_notice, null);        ImageView iv_head_pic = (ImageView) noticeView.findViewById(R.id.iv_head_pic);        TextView tv_name = (TextView) noticeView.findViewById(R.id.tv_name);        TextView tv_content = (TextView) noticeView.findViewById(R.id.tv_content);        TextView tv_time = (TextView) noticeView.findViewById(R.id.tv_time);        if ((curr < next) && (next > (data.size() - 1))) {            next = 0;        } else if ((curr > next) && (next < 0)) {            next = data.size() - 1;        }        Picasso.with(this).load(data.get(next).picurl)                .placeholder(R.drawable.img_res_logo)                .error(R.drawable.img_res_logo)                .into(iv_head_pic);        tv_name.setText(data.get(next).nickname + " 获得");        tv_content.setText(data.get(next).prize_name);        tv_time.setText(Tools.formatTime(data.get(next).time));        if (vf_notice.getChildCount() > 1) {            vf_notice.removeViewAt(0);        }        vf_notice.addView(noticeView, vf_notice.getChildCount());        mCurrPos = next;    }

两个动画:

in_bottom

<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_top

<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>

Item的点击事件

    if(vf_notice.getDisplayedChild()==0){                  vf_notice.getCurrentView().setOnClickListener(new OnClickListener() {                      @Override                      public void onClick(View arg0) {                          // TODO Auto-generated method stub                      }                  });              }  
//取消task 可要可不要   @Override    protected void onDestroy() {        super.onDestroy();        if (task != null) {            task.cancel();            timer.cancel();            timer = null;        }    }

这里再保存一个别人写的方法:

TextView滚动效果

上下滚动

参考文章:
[Android] 使用 ViewFlipper 实现上下循环滚动通知栏

更多相关文章

  1. Android:横行滚动且隔行变色的ListView控件
  2. android ScrollView--Linearlayout可以上下拖动
  3. Android(安卓)- 保持在底部的按钮栏,上面是滚动的ScrollView
  4. Android之菜单总结
  5. android HorizontalScrollView实现滚动监听
  6. TextView跑马灯效果
  7. Android上下文服务管理查询过程
  8. [置顶] Android(安卓)自定义UI文章汇总
  9. Android从网上下载文件

随机推荐

  1. MySQL查询中的变量会导致错误
  2. mysql字符集浅谈
  3. 反驳"MySQL InnoDB (不行)的性能问题",千
  4. 在同一列上选择多个条件
  5. MYSQL必知必会-SQL语句查询
  6. 《高性能MySQL》学习笔记一
  7. mysql数据版本控制系统的最佳实践
  8. Log4j2记录日志到数据库(MySQL&MongoDB)
  9. php mysql有条件地将行插入到不同的表中
  10. MySQL架构:空列与联接