怎么在Android中自定义ViewFlipper实现一个滚动效果

  介绍

这期内容当中小编将会给大家带来有关怎么在Android中自定义ViewFlipper实现一个滚动效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

Android是什么

Android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。

代码:

public  class  ViewFlipper  extends  LinearLayout  {   ,   ,private  final  int  MAX_SHOW_ITEM_SIZE =, 5;   ,   ,private  IAdapter  mIAdapter;   ,   ,private  int  mCount;   ,   ,//最后一个项目动画   ,private  Animation  mLastOneAnimation;   ,   ,//其它项动画   ,private  Animation  mCommonAnimation;   ,   ,//数据下标   ,private  int  mCurrentIndex;   ,/* *   *,才能这里动画时间是1600毫秒,所以间隔得大于动画时间   ,*/,private  static  final  int  DEFAULT_INTERVAL =, 2000;   ,   ,private  int  mFlipInterval =, DEFAULT_INTERVAL;   ,   ,private  boolean  mAutoStart =,假;   ,   ,private  boolean  mRunning =,假;   ,private  boolean  mStarted =,假;   ,private  boolean  mVisible =,假;   ,private  boolean  mUserPresent =,真的;   ,   ,public  ViewFlipper (Context 上下文),{   超级才能(上下文);   初始化才能(上下文);   ,}   ,   ,public  ViewFlipper (Context 上下文,AttributeSet  attrs), {   超级才能(上下文,attrs);   初始化才能(上下文);   ,}   ,   ,public  ViewFlipper (Context 上下文,AttributeSet  attrs,, int  defStyleAttr), {   超级才能(上下文,attrs,, defStyleAttr);   初始化才能(上下文);   ,}   ,   ,private  final  BroadcastReceiver  mReceiver =, new  BroadcastReceiver (), {   @Override才能   public 才能;void  onReceive (Context 上下文,Intent 意图),{   ,,final  String  action =, intent.getAction ();   ,,if  (Intent.ACTION_SCREEN_OFF.equals(行动),{   ,,,mUserPresent =,假;   ,,,updateRunning ();   ,,},else  if  (Intent.ACTION_USER_PRESENT.equals(行动),{   ,,,mUserPresent =,真的;   ,,,updateRunning(假);   ,,}   ,,}   ,};   ,   ,@Override   ,protected  void  onAttachedToWindow (), {   super.onAttachedToWindow才能();   ,//才能,Listen  for  broadcasts  related 用用户上线   final 才能IntentFilter  filter =, new  IntentFilter ();   filter.addAction才能(Intent.ACTION_SCREEN_OFF);   filter.addAction才能(Intent.ACTION_USER_PRESENT);   ,//,,,好的,,却;能够is  gross  but 只需要却;能够class  is  supported  by //才能,remote  views  machanism 以及as  a  part  of  that 从而remote 观点//才能,还要be  inflated  by  a  context  for  another  user  without 从而应用//才能,having  interact  users  permission 作用;just  for  loading 资源。//才能,For 例子,,when  adding  widgets 得到a  user  profile 用//才能,home 屏幕又是;因此,register 我方表示歉意,receiver  as 从而电流//才能,user  not 从而one 从而context  is 。   ,,getContext () .registerReceiver (mReceiver,,过滤器);   ,   if 才能;(mAutoStart), {   ,,//,Automatically  start  when 请求   ,,startFlipping ();   ,,}   ,}   ,   ,@Override   ,protected  void  onDetachedFromWindow (), {   super.onDetachedFromWindow才能();   时间=mVisible 才能;假;   ,   ,,getContext () .unregisterReceiver (mReceiver);   updateRunning才能();   ,}   ,   ,@Override   ,protected  void  onWindowVisibilityChanged (int 可见性),{   super.onWindowVisibilityChanged才能(能见度);   时间=mVisible 才能;visibility ==,可见;   updateRunning才能(mVisible);//,,updateRunning(假);   ,}   ,   ,private  void  init (Context 上下文),{   this.setOrientation才能(LinearLayout.VERTICAL);   ,}   ,   ,public  void  setIAdapter (IAdapter  iAdapter), {   时间=this.mIAdapter 才能;iAdapter;   initShowItems才能();   ,}   ,   ,public  void  startFlipping (), {   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在Android中自定义ViewFlipper实现一个滚动效果