使用ViewFlipper实竖直方向上的轮播(任意view)
来源:互联网 发布:php java哪个好学 编辑:程序博客网 时间:2024/06/10 03:00
ViewFlipper自带轮播功能,可以设置间隔时间,item进去和退出的动画;
ViewFlipper添加需要滚动的view。
demo的思路:自定义ViewFlipper,初始化中设置它的滚动间隔时间,进去和结束的动画,然后在数据源的set方法中添加textview和imageview
public class MViewFlipper extends ViewFlipper { OnCheckedListener onCheckedListener; public void setOnCheckedListener(OnCheckedListener onCheckedListener) { this.onCheckedListener = onCheckedListener; } Context mContext; List<String> allData; public interface OnCheckedListener { void onClick(int position); } public MViewFlipper(Context context) { super(context); } public MViewFlipper(Context context, AttributeSet attrs) { super(context, attrs); initView(context); } private void initView(Context context) { mContext = context; //间隔时间 setFlipInterval(3000); //设置间隔 setPadding(5, 5, 5, 5); //设置进入和出去的动画//出去的动画 AnimationSet animationSetOut = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); // alphaAnimation.setStartOffset(500); TranslateAnimation translateAnimation = new TranslateAnimation(getX(), getX(), 0, -100); animationSetOut.addAnimation(translateAnimation); animationSetOut.addAnimation(alphaAnimation); animationSetOut.setDuration(1000); setOutAnimation(animationSetOut); //进来的动画 AnimationSet animationSetIn = new AnimationSet(true); AlphaAnimation alphaAnimation1 = new AlphaAnimation(0, 1); // alphaAnimation1.setStartOffset(500);设置延迟执行动画 TranslateAnimation translateAnimatio1n = new TranslateAnimation(getX(), getX(), 100, 0); animationSetIn.addAnimation(translateAnimatio1n); animationSetIn.addAnimation(alphaAnimation1); animationSetIn.setDuration(1000); setInAnimation(animationSetIn); } public void setAllData(List<String> allData) { this.removeAllViews(); this.allData = allData; //把数据添加到viewflipper里面 for (int i = 0; i < allData.size(); i++) { TextView textView = new TextView(mContext); final int finalI = i; textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onCheckedListener.onClick(finalI); } }); textView.setSingleLine(); textView.setTextSize(17.0f); textView.setText(allData.get(i)); textView.setTextColor(Color.parseColor("#FF4081")); textView.setGravity(Gravity.CENTER); addView(textView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ImageView imageView = new ImageView(mContext); imageView.setBackgroundDrawable(getResources().getDrawable(R.mipmap.ic_launcher)); addView(imageView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } }}
阅读全文
1 0
- 使用ViewFlipper实竖直方向上的轮播(任意view)
- ViewFlipper竖直方向可以自动滚动的空间
- 使用ViewFlipper实现图片的轮播
- 判断 View 在竖直方向上能否滑动
- 3.ViewFlipper的使用(上下翻滚轮播效果)
- 自定义竖直方向的seekbar(一)
- android ViewFlipper使用——轮播制作(一)
- 使用ViewFlipper实现图片轮播
- ViewFlipper实现View轮播点击等效果
- QT实现竖直方向的窗口布局(使用QLayout类)
- ViewFlipper实现图片的轮播
- 自定义竖直方向的ViewPager
- 文字竖直方向的滚动
- 给可滚动的View 添加头部,解决竖直方向的事件冲突
- 安卓两个竖直方向滑动的view嵌套,解决事件冲突
- Android中的ViewFlipper的简单使用------自动轮播
- viewFlipper的使用实现自动轮播广告图片
- android API Demo之使用ViewFlipper制作轮播广告
- python中两个List比较
- Java-未完待续
- iOS应用架构谈(4) 本地持久化方案及动态部署
- eclipse新建工作空间(workspace)初试设置
- 仿Win8的磁贴效果
- 使用ViewFlipper实竖直方向上的轮播(任意view)
- iOS CoreData数据迁移-默认迁移方式
- 串口通信的基本知识
- JAVA运算符
- 【QT】更改默认路径
- 长度为n的数组,有一个数m重复出现了n/2+1次,找出这个数
- Linux下的串口调试助手minicom的使用
- PHP 简介
- SVM的函数距离和几何距离