ViewFlow

一般不直接使用ViewAnimator而是使用它的两个子类ViewFlipper和ViewSwitcher。

  
  • ViewSwitcher allows only two views, while ViewFlipper allows more. ViewSwitcher is Useful if you have 2 Views that you have to go back and forth fairly regularly. if you want features like the ViewFactory and you only got 2 views use the ViewSwitcher. ViewSwitcher is used in circumstances where the view is the same but the data is different – like on a calendar app – we’re just changing the data in the view.
  • ViewFlipper can be used if you want to periodically change the views. Say like an automated flipping book of some sort. Though a custom-adapter gallery is much better at this.
  • with ViewPager, each “page” is itself a Fragment.
通过android.view.GestureDetector类可以检测各种手势事件,该类有两个回调接口分别用来通知具体的事件:
     GestureDetector.OnDoubleTapListener:用来通知DoubleTap事件,类似于鼠标的双击事件,该接口有如下三个回调函数:
  1. onDoubleTap(MotionEvent e):通知DoubleTap手势,
  2. onDoubleTapEvent(MotionEvent e):通知DoubleTap手势中的事件,包含down、up和move事件(这里指的是在双击之间发生的事件,例如在同一个地方双击会产生DoubleTap手势,而在DoubleTap手势里面还会发生down和up事件,这两个事件由该函数通知);
  3. onSingleTapConfirmed(MotionEvent e):用来判定该次点击是SingleTap而不是DoubleTap,如果连续点击两次就是DoubleTap手势,如果只点击一次,OPhone系统等待一段时间后没有收到第二次点击则判定该次点击为SingleTap而不是DoubleTap,然后触发SingleTapConfirmed事件
GestureDetector.OnGestureListener:用来通知普通的手势事件,该接口有如下六个回调函数:
  1. onDown(MotionEvent e):down事件;
  2. onSingleTapUp(MotionEvent e):一次点击up事件;
  3. onShowPress(MotionEvent e):down事件发生而move或则up还没发生前触发该事件;
  4. onLongPress(MotionEvent e):长按事件;
  5.  onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY):滑动手势事件;
  6. onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY):在屏幕上拖动事件。

ViewFlow=ViewFlipper + ScrollView

ViewFlow 相当于 Android UI 部件提供水平滚动的 ViewGroup,例如ViewPager或是ViewFlipper,它也使用 Adapter 进行条目绑定。提供了可以动态添加View的功能,也就是说如果你的View数目是不固定的,那么你就应该使用ViewFlow,如果数目固定,就没有必要使用,因为有ViewPager或者Fragment。所以,说白了这个项目就是用来解决ViewPager不能动态添加View的问题,或者说是一个拓展。这个项目的网址是: https://github.com/pakerfeldt/android-viewflow
它提供了三个组件ViewFlow、FlowIndicatorTitleFlowIndicator。它使得由Adapter产生的ViewGroup中的View可以水平滑动。把example改改就可以根据自己的需要来应用了。
如何使用ViewFlow?

首先在你的layout文件中加入:

<org.taptwo.android.widget.ViewFlow

 android:id=”@+id/viewflow”

app:sidebuffer=”5″/>

其中app:sidebuffer属性是ViewFlow组件自定义的,使用这些属性时,需要增加如下的xml的命名空间

xmlns:app=”http://schemas.android.com/apk/res/your.application.package.here

然后在你的Activity里面添加如下代码用于使用ViewFlow:
ViewFlow viewFlow = (ViewFlow) findViewById(R.id.viewflow);
viewFlow.setAdapter(myAdapter);//or 设置初始view的位置 viewFlow.setAdapter(myAdapter, 8);
//监听view切换事件,简单的需求可不监听
viewFlow.setOnViewSwitchListener(new ViewSwitchListener()
{ public void onSwitched(View v, int position) { / / Your code here 16 17 } });

你也可以使用该库中的FlowIndicator为你在多个view中切换时提供一个指示器,目前该库已经实现了两种指示器:一种是圆点指示器FlowIndicator;另一种是标题指示器TitleFlowIndicator
  • 圆点指示器还支持activeColor、inactiveColor、activeType(填充或描边)、inactiveType(填充或描边)、fadeOut(设置圆点自动隐藏的秒数,若为0则不会自动隐藏)、radius(圆点的半径)等。
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: