转载请注明出处:王亟亟的大牛之路

时间过得非常快,这一系列已经写了第五篇了(感觉还要写好久)。今天又引入了2个非常好用的库JumpingBeans,ConvenientBanner.首先。先看一下效果。

1.这2个控件做了什么?

JumpingBeans是载入页面时那个蓝色跳动的动画效果。

JumpingBeans:https://github.com/frakbot/JumpingBeans

ConvenientBanner是滚动的那个广告栏。

ConvenientBanner:https://github.com/saiwu-bigkoo/Android-ConvenientBanner

2.怎么下载?

  compile 'net.frakbot:jumpingbeans:1.3.0'
compile 'com.bigkoo:convenientbanner:1.1.4'

3.为什么要用?

TextView之类的控件的跳动能够用动画实现。甚至能够拼接多个控件然后依据运算进行位置的模拟变化。可是JumpingBeans封装的更简单。非常方便我们使用。

滚动的广告栏差点儿在大多数的线上产品中都有出现(诸如ViewPager+Fragment)。ConvenientBanner对本地/网络的情况都做了简单有用的处理,让我们省去了换算时间,监听注冊一系列反复低效的操作。


接下来我们来说下怎样使用

JumpingBeans

a.还是正常的一个TextView像这样:

  <TextView
android:id="@+id/jumpTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/circleProgressBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="加 载 中 。 。 "
android:textColor="@color/DoderBlue"
android:textSize="20dp" />

b.然后和往常一样findViewByIdjumpTextView = (TextView) findViewById(R.id.jumpTextView);

c.声明一个JumpingBeans 对象private JumpingBeans jumpingBeans;

d.然后对动画效果进行设置,我们来看一下怎么实现的

jumpingBeans = JumpingBeans.with(jumpTextView)

.makeTextJump(0, jumpTextView.getText().toString().indexOf(' '))

.setIsWave(true)

.setLoopDuration(800) // ms

.build();

e.把这个TextView绑定到JumpingBeans 中

  public static Builder with(@NonNull TextView textView) {
return new Builder(textView);
}

详细动作的哪几个字如传入(0,3)就是第1-第4个字有动画效果

   public Builder makeTextJump(int startPos, int endPos) {
CharSequence text = textView.getText();
ensureTextCanJump(startPos, endPos, text); this.text = text;
this.wave = true;
this.startPos = startPos;
this.endPos = endPos; return this;
}

对makeTextJump方法传入參数的检验,以保证不会start>end这样的情况

    private static CharSequence ensureTextCanJump(int startPos, int endPos, CharSequence text) {
if (text == null) {
throw new NullPointerException("The textView text must not be null");
} if (endPos < startPos) {
throw new IllegalArgumentException("The start position must be smaller than the end position");
} if (startPos < 0) {
throw new IndexOutOfBoundsException("The start position must be non-negative");
} if (endPos > text.length()) {
throw new IndexOutOfBoundsException("The end position must be smaller than the text length");
}
return text;
}

是否同意有动画

  public Builder setIsWave(boolean wave) {
this.wave = wave;
return this;
}

效果持续的时间,毫秒为单位

public Builder setLoopDuration(int loopDuration) {
if (loopDuration < 1) {
throw new IllegalArgumentException("The loop duration must be bigger than zero");
}
this.loopDuration = loopDuration;
return this;
}

推断一系列參数,构建效果并运行(又一次对TextView的字符串内容进行拼接)

   public JumpingBeans build() {
SpannableStringBuilder sbb = new SpannableStringBuilder(text);
JumpingBeansSpan[] spans;
if (wave) {
spans = getJumpingBeansSpans(sbb);
} else {
spans = buildSingleSpan(sbb);
} textView.setText(sbb);
return new JumpingBeans(spans, textView);
}

f.结束时记得把开启的动画关了,不然内存泄漏你懂的,调用stopJumping()

  public void stopJumping() {
for (JumpingBeansSpan bean : jumpingBeans) {
if (bean != null) {
bean.teardown();
}
} cleanupSpansFrom(textView.get());
}

使用起来 是不是非常easy?


ConvenientBanner

a.先放一个控件,仅仅须要一个哦!一般实现的方式须要布局的ViewPager fragment之类的还要标签点的imageview等等还是蛮麻烦的。

<com.bigkoo.convenientbanner.ConvenientBanner
android:id="@+id/convenientBanner"
android:layout_width="match_parent"
android:layout_height="200dp"
app:canLoop="true"/>

b.声明private ConvenientBanner convenientBanner;

c.获取控件convenientBanner = (ConvenientBanner) findViewById(R.id.convenientBanner);

d.对详细的内容进行设置:

//自己定义你的Holder。实现很多其它复杂的界面。不一定是图片翻页,其它不论什么控件翻页亦可。
convenientBanner.setPages(
new CBViewHolderCreator<LocalImageHolderView>() {
@Override
public LocalImageHolderView createHolder() {
return new LocalImageHolderView();
}
}, localImages)
//设置两个点图片作为翻页指示器。不设置则没有指示器,能够依据自己需求自行配合自己的指示器,不须要圆点指示器可用不设
.setPageIndicator(new int[]{R.drawable.ic_page_indicator, R.drawable.ic_page_indicator_focused})
//设置指示器的方向
.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT)
//设置翻页的效果,不须要翻页效果可用不设
.setPageTransformer(Transformer.DefaultTransformer);
// convenientBanner.setManualPageable(false);//设置不能手动影响 public class LocalImageHolderView implements CBPageAdapter.Holder<Integer>{
private ImageView imageView;
@Override
public View createView(Context context) {
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
return imageView;
} @Override
public void UpdateUI(Context context, final int position, Integer data) {
imageView.setImageResource(data);
}
}

https://github.com/saiwu-bigkoo/Android-ConvenientBanner有详细的Demo (而且,项目仍在维护其中,感谢作者https://github.com/saiwu-bigkoo)

Soyi项目代码地址:https://github.com/ddwhan0123/SoyiGit

观众老爷麻烦点个赞。谢谢你的支持

整合大量开源库项目(五)跳动的TextView JumpingBeans,良好体验的滚动条ConvenientBanner的更多相关文章

  1. 整合大量开源库项目(八)能够载入Gif动画的GifImageView

    转载请注明出处王亟亟的大牛之路 上周大多数时间都是依据兴起,想到什么做什么写了几个自己定义控件,把Soyi丢在那没怎么动,今天就把写的东西整合进来,顺便把SOyi"个人研发的结构理一下&qu ...

  2. Android开源库项目集锦

    一.兼容类库 ActionBarSherlock : Action Bar是Android 3.0后才開始支持的,ActionBarSherlock是让Action Bar功能支持2.X后的全部平台. ...

  3. iOS项目中常用的第三方开源库

    1.项目使用的第三方开源库 项目使用了CocoaPods(类似java中的maven)管理常用的第三方库,一些特殊的单独引用,下面介绍下比较好用的几个. (1)AFNetworking 目前比较推荐的 ...

  4. 第三方开源库和jar包的区别

    jar包和第三方开源库的根本区别在于,开源库的功能比jar包功能更强大,通过引入库项目可以访问java文件以及该开源库项目下的资源文件,例如图片,layout等文件 jar包中只能放class文件 引 ...

  5. iOS 项目中用到的一些开源库和第三方组件

    iOS 项目中用到的一些 iOS 开源库和第三方组件 分享一下我目前所在公司 iOS 项目中用到的一些 iOS 开源库和第三方组件, 感谢开源, 减少了我们的劳动力, 节约了我们大量的时间, 让我们有 ...

  6. Android 开源库和项目 3

    Android 开源库和项目 Android 开源库和项目 2 1.Matisse Android 图片选择器 -- 知乎开源 github 地址:https://github.com/zhihu/M ...

  7. 如何在Android Studio项目中导入开源库?

    前两天,谷歌发布了Android Studio 1.0的正式版,也有更多的人开始迁移到Android Studio进行开发.然而,网上很多的开源库,控件等还是以前的基于Eclipse进行开发,很多人不 ...

  8. AndroidStudio怎样导入library项目开源库

    AndroidStudio是一款非常强大的android程序开发软件,在里面集成了几乎所有android开发中需要使用的工具,编译.运行.打包.开发.调试等功能一应俱全,可以使用起来非常方便. 今天要 ...

  9. Tornadofx学习笔记(4)——IconTextFx开源库,整合5000+个字体图标

    JavaFx中其实也可以直接使用字体图标iconfont的,只需要加载ttf字体文件,之后设置unicode即可,具体可以看我给出的代码 既然JavaFx可以,那么以JavaFx为基础的Tornado ...

随机推荐

  1. array_combine php一个比较偏门的数组函数

    这函数  返回数组1的值 当做key,把数组2的值当做value,   当查询数据库用了 group +GROUP_CONCAT 两个组合时,(例如查询某个班级的,用户名,用户id,返回的是字符串,打 ...

  2. 为什么要重写toString()方法

    因为在System.out.println(类的对象名)时,类的对象名是个引用,如果不重写,就输出引用地址. 其实实际是这样的System.out.println(类的对象名.toString()), ...

  3. java整型byte,short,int,long取值范围大小

     byte 1个字节 short 2个字节 int 4个字节long 8 个字节 varchar 可变长度的非Unicode数据,最长为8000个字符nvarchar 可变长度Unicode数据,最长 ...

  4. Redis windows版本的启停bat脚本命令

    Reids windows版本安装 redis windows官网推荐:https://github.com/MicrosoftArchive/redis/releases 下载解压即可. 启停bat ...

  5. myeclipse导入工程 Some projects cannot be imported because they already exist in the workspace

    问题描述: 1 第一次从外部导入工程或者新建工程,成功: 2 删除该工程,但是没有选择delete project contents on disk 3 再次需要该工程,导入该工程时出现警告:Some ...

  6. FreeRTOS系列第13篇---FreeRTOS内核控制

    内核控制的一些功能须要移植层提供,为了方便移植.这些API函数用宏来实现,比方上下文切换.进入和退出临界区.禁止和使能可屏蔽中断.内核控制函数还包含启动和停止调度器.挂起和恢复调度器以及用于低功耗模式 ...

  7. PHP中用下标符号[]去读取字符串的逻辑

    PHP中 [(下标)] 符号不仅能够应用于数组和对象,还能够应用于字符串,假设不注意非常easy出错. 比方获取一个网络接口,正常情况下会返回一个数组结构的json,经过解析之后结果为: array( ...

  8. 【LeetCode】Palindrome Partitioning 解题报告

    [题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...

  9. pjlib深入剖析和使用详解

    1. PJSIP简介 PJSIP的实现是为了能在嵌入式设备上高效实现SIP/VOIP.其主要特征包括:    1).极具移植性.(Extremely portable)                 ...

  10. Matplotlib画图可选颜色

    经常会有画图找不到合适颜色的尴尬情景, 在网上找到一张matplotlib可以用的颜色图: