android 使用ViewFlow实现左右滑动
2013-08-06 11:59
375 查看
一、使用ViewFlow库
那么什么时候可以使用这个组件呢?文档上说,当你需要在一系列不确定数目的view中滑动时,可以考虑使用ViewFlow。如果你的view数目确定,你应该使用Fragments或兼容库里的1、使用ViewFlow
怎么使用呢?首先在你的layout文件中加入:
1 2 3 4 | <</CODE> [code]android:id = "@+id/viewflow" app:sidebuffer = "5" /> |
1 | xmlns:app=" |
1 2 3 4 5 6 7 8 9 10 | ViewFlowviewFlow=(ViewFlow)findViewById(R.id.viewflow); viewFlow.setAdapter(myAdapter); //设置初始view的位置 //viewFlow.setAdapter(myAdapter,8); //监听view切换事件,简单的需求可不监听 viewFlow.setOnViewSwitchListener( new ViewSwitchListener(){ public void onSwitched(Viewv, int position){ //Yourcodehere } }); |
2、使用圆点指示器
圆点指示器可以这样使用:
先在layout中这样定义
1 2 3 4 | <</CODE> [code]android:padding = "10dip" android:layout_height = "wrap_content" android:layout_width = "wrap_content" android:id = "@+id/viewflowindic" android:background = "#00000000" /> |
1 2 3 | CircleFlowIndicatorindic=(CircleFlowIndicator) findViewById(R.id.viewflowindic); viewFlow.setFlowIndicator(indic); |
3、使用标题指示器
标题指示器也是先layout里定义:
1 2 3 4 5 6 7 8 9 10 11 | <</CODE> [code]android:id = "@+id/viewflowindic" android:layout_height = "wrap_content" android:layout_width = "fill_parent" app:footerLineHeight = "2dp" app:footerTriangleHeight = "10dp" app:textColor = "#FFFFFFFF" app:selectedColor = "#FFFFC445" app:footerColor = "#FFFFC445" app:titlePadding = "10dp" app:textSize = "11dp" app:selectedSize = "12dp" android:layout_marginTop = "10dip" app:clipPadding = "5dp" /> |
1 2 3 4 | TitleFlowIndicatorindicator=(TitleFlowIndicator) findViewById(R.id.viewflowindic); indicator.setTitleProvider(myTitleProvider); viewFlow.setFlowIndicator(indicator); |
要注意的是,如果你使用的androidsdk版本是android2.2以下,最好在activity中加上如下方法
1 2 3 4 5 | @Override public void onConfigurationChanged(ConfigurationnewConfig){ super .onConfigurationChanged(newConfig); viewFlow.onConfigurationChanged(newConfig); } |
网友
滑动循环功能通过在adapter的getcount方法要返回Integer.Max_value。然后在getview方法中,由于position不断递增,可以取余数。并调用viewflow.setSelection(3*图片数)来实现循环。
自动播放是通过如下代码实现的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | //通过延迟消息实现自动播放,使用时通过调用该方法来启动自动播放功能 public void startAutoFlowTimer(){ handler= new Handler(){ @Override public void handleMessage(Messagemsg){ snapToScreen((mCurrentScreen+ 1 )%getChildCount()); Messagemessage=handler.obtainMessage( 0 ); sendMessageDelayed(message,timeSpan); } }; Messagemessage=handler.obtainMessage( 0 ); handler.sendMessageDelayed(message,timeSpan); } |
相关文章推荐
- android 使用ViewFlow实现图片带焦点左右滑动(定时滑动)
- android 使用ViewFlow实现左右滑动
- android 使用ViewFlow实现左右滑动
- Android 仿美团网,探索使用ViewPager+GridView实现左右滑动查看更多分类的功能
- Android:使用ViewPager实现左右滑动切换图片(图上有点点)
- Android使用ViewPager实现左右循环滑动及轮播效果
- android ViewPager,ViewFlipper,ViewFlow实现左右滑动
- android ViewPager,ViewFlipper,ViewFlow实现左右滑动
- Android 使用ViewPager实现左右循环滑动图片
- android-使用ViewGroup实现左右滑动切换界面以及界面裂开的效果
- Android 使用ViewPager实现左右循环滑动图片
- Android实现左右滑动指引效果(使用ViewPager)
- 【代码】Android ViewFlow 实现左右滑动
- 在Android中使用ViewPager实现左右滑动页面
- 【转】android ViewPager,ViewFlipper,ViewFlow实现左右滑动
- Android 使用ViewPager实现左右循环滑动图片
- Android使用ViewFlipper实现左右滑动效果面
- 【android】ViewPager的使用——实现左右滑动(下方带圆点)
- Android实现左右滑动指引效果(使用ViewPager)
- android ViewPager,ViewFlipper,ViewFlow实现左右滑动