`
xyz_lmn
  • 浏览: 65502 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Android UI开发第十三篇——android-viewflow

 
阅读更多
在论坛里,经常看到有人问如何实现UC或墨迹天气那样的拖动效果。其实大部分的实现都是参考了Launcher里的Workspace这个类。刚好看到有个开源项目也是实现了这种功能,地址在http://code.google.com/p/andro-views/,希望对有需要的人有所帮助,做出很cool的应用出来。

View Flow for Android

ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter. Scroll down to the bottom of the page for a screen shot.

The component is a Library Project. This means that there's no need to copy-paste resources into your own project, simply add the viewflow component as a reference to any project.

Usage

In your layout

<org.taptwo.android.widget.ViewFlow
    android:id="@+id/viewflow"
    app:sidebuffer="5"
    />

The use of app:sidebuffer is optional. It defines the number of Views to buffer on each side of the currently shown View. The default sidebuffer is 3, making up a grand total of 7 (3 * 2 + 1) Views loaded at a time (at max). To be able to use the more convenient app:sidebuffer attribute, the application namespace must be included in the same manner as the android namespace is. Please refer to the layout main.xml in the example project for a full example. Again, note that it's the application namespace and not the viewflow namespace that must be referred like xmlns:app="http://schemas.android.com/apk/res/your.application.package.here".

In your activity

ViewFlow viewFlow = (ViewFlow) findViewById(R.id.viewflow);
viewFlow.setAdapter(myAdapter);

Setting a different initial position (0 being default) is as easy as:

viewFlow.setAdapter(myAdapter, 8);

Although possible, you should not call setSelection(...) immediately after callingsetAdapter(myAdapter) as that might load unnecessary views giving you a decrease in performance.

Listen on screen change events

If you need to listen to screen change events you would want to implement your ownViewFlow.ViewSwitchListener and pass it to the setOnViewSwitchListener() method.

viewFlow.setOnViewSwitchListener(new ViewSwitchListener() {
    public void onSwitched(View v, int position) {
        // Your code here
    }
});

Flow Indicator

It is also possible to add a flow view indicator to your layout. The purpose of aFlowIndicator is to present a visual representation of where in the item list focus is at. You may either implement aFlowIndicator yourself or use an implementation provided by the View Flow library. The View Flow library currently supports the following indicators:

Circle Flow Indicator

This indicator shows a circle for each View in the adapter with a special circle representing the currently selected view (see screenshot below).

<org.taptwo.android.widget.CircleFlowIndicator
    android:padding="10dip" android:layout_height="wrap_content"
    android:layout_width="wrap_content" android:id="@+id/viewflowindic"
    android:background="#00000000"/>

And then you'll need to connect your ViewFlow with the FlowIndicator:

CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic);
viewFlow.setFlowIndicator(indic);

The following attributes are supported: activeColor, inactiveColor,activeType (either fill or stroke), inactiveType (either fill or stroke),fadeOut (time in ms until indicator fades out, 0 = never), radius.

Title Flow Indicator

This indicator presents the title of the previous, current and next View in the adapter (see screenshot below).

    <org.taptwo.android.widget.TitleFlowIndicator
        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" />

And then you'll need to connect your ViewFlow with the FlowIndicator:

    TitleFlowIndicator indicator = (TitleFlowIndicator) findViewById(R.id.viewflowindic);
    indicator.setTitleProvider(myTitleProvider);
    viewFlow.setFlowIndicator(indicator);

Building a jar file

If you rather want a jar file instead of a including the project as an android library, runant jar in the android-viewflow/viewflow folder, to build a jar file.

Caveats

The manifest states a min sdk version of 4, which is true. But in any case you want to support an api level < 8 you will have to forward anonConfigurationChanged event to the ViewFlow from your Activity. I know this isn't a very nice solution, feel free to propose better ones!

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        viewFlow.onConfigurationChanged(newConfig);
    }

Contributions

The following persons deserves a mention for their contributions:

Want to contribute?

GitHub has some great articles on how to get started with Git and GitHub and how to fork a project.

Contributers are recommended to fork the app on GitHub (but don't have too). Create a feature branch, push the branch to git hub, press Pull Request and write a simple explanation.

One fix per commit. If let's say a commit closes the open issue 12. Just add closes #12 in your commit message to close that issue automagically.

If you still feel uncomfortable contributing the project github-wise, don't hesistate to send a regular patch.

All code that is contributed must be compliant with Apache License 2.0.

License

Copyright (c) 2011 Patrik Åkerfeldt

Licensed under the Apache License, Version 2.0

ViewFlow for AndroidViewFlow for Android


/**
* @author 张兴业
* 邮箱:xy-zhang#163.com
* android开发进阶群:278401545
*
*/

分享到:
评论

相关推荐

    PyPI 官网下载 | django-viewflow-0.3.0.tar.gz

    在Python的开发环境中,`PyPI`(Python Package Index)是官方的第三方软件仓库,它提供了丰富的Python库供开发者下载和使用。`django-viewflow-0.3.0.tar.gz`这个资源就是从PyPI官网上获取的一个压缩包,它包含了名...

    android-viewflow-maste

    了解并掌握ViewFlow组件对于Android开发者来说非常有价值,特别是在创建具有动态内容和横向导航需求的UI时。它不仅简化了开发过程,还能为用户提供一致且流畅的交互体验。同时,开源的特性使得开发者可以自由地对其...

    14.[开源][安卓][视图切换的效果库]android-viewflow-master

    14.[开源][安卓][视图切换的效果库]android-viewflow-master android-viewflow是Android平台上的一个视图切换的效果库,ViewFlow相当于Android UI部件提供水平滚动的ViewGroup,使用Adapter进行条目绑定。

    Android应用源码之ltc_viewflow-dem-IT计算机-毕业设计.zip

    本篇将对"ltc_viewflow-dem"这个Android应用源码进行深入解析,帮助读者理解Android应用开发的核心技术和流程。 首先,"ltc_viewflow-dem"这个名字中的"ViewFlow"是一个常见的Android UI组件,它提供了一种平滑的...

    安卓Android源码——viewflow视图切换效果.zip

    在安卓开发中,ViewFlow是一种流行且实用的控件,用于实现类似Pinterest的平滑滚动视图切换效果。它允许用户在多个视图之间轻松滑动,为应用程序提供了一个动态和用户友好的界面。本资源包含`viewflow-example`和`...

    Android高级应用源码-ViewFlow,一个滑动效果库.zip

    【标题】"Android高级应用源码-ViewFlow,一个滑动效果库.zip"指的是一个针对Android平台的开源项目,名为ViewFlow。这个库提供了一种实现平滑滑动效果的方法,通常用于创建类似iOS中TabBar的效果,允许用户在多个...

    android-viewflow框架.zip

    `android-viewflow`框架是一个专为Android平台设计的视图流布局库,它允许开发者创建一个平滑且可滚动的视图序列,类似于iOS中的`UIPageViewController`。这个框架的核心概念是提供一种简单的方式来展示大量的视图,...

    viewflow-视图切换

    "viewflow-视图切换" 是一个专门为Android平台设计的视图切换效果库,它为开发者提供了更加丰富和流畅的用户界面体验。在Android应用开发中,视图切换是一个常见的需求,例如在滑动浏览、Tab切换或者多面板展示等...

    安卓Android源码——ViewFlow,一个滑动效果库.rar

    在安卓开发中,为了提供丰富的用户交互体验,开发者经常需要借助第三方库来实现特定功能,例如滑动切换页面的效果。ViewFlow就是一个专为Android设计的滑动效果库,它允许用户轻松地创建类似iOS中SegmentControl的...

    安卓Android源码——ViewFlow,一个滑动效果库.zip

    在安卓应用开发中,ViewFlow是一个非常实用的第三方库,它为开发者提供了类似iOS中UIPageControl的滑动效果。这个库使得用户可以方便地在多个视图之间平滑地左右滑动,常用于创建类似瀑布流或者标签页的效果。在...

    android-viewflow

    由于其高度可定制性和易用性,ViewFlow在许多Android应用开发中被广泛采用。 在`android-viewflow-master`这个压缩包中,你将找到ViewFlow的源代码、示例项目和其他相关资源。通过阅读源码,你可以深入理解ViewFlow...

    应用源码之ltc_viewflow-dem.zip

    本篇文章将围绕“ltc_viewflow-dem”这一源码项目进行详细解读,帮助读者理解其背后的JAVA编程原理、毕业设计思路以及在ANDROID平台上的实际应用。我们将探讨该源码中的关键组件、设计模式以及实现机制,力求让读者...

    Android应用源码之ltc_viewflow-demo.rar

    总结,`ltc_viewflow-demo`项目是一个极好的学习资源,它涵盖了Android应用开发中的许多重要概念,如自定义视图、适配器模式、事件处理、布局设计等。对于想要深入理解Android UI编程的开发者来说,这是一个宝贵的...

    基于django-viewflow的动态任务分配与流程管理设计源码

    该项目是基于Django-Viewflow的动态任务分配与流程管理设计源码,包含23个文件,包括16个Python源文件、4个XML配置文件、2个Git忽略文件和1个Idea项目配置文件。该系统实现了流程的动态任务分配和所有者管理功能,...

    Android应用源码之ltc_viewflow-dem.zip项目安卓应用源码下载

    Android应用源码之ltc_viewflow-dem.zip项目安卓应用源码下载Android应用源码之ltc_viewflow-dem.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考

Global site tag (gtag.js) - Google Analytics