在github上有一个开源项目:JumpingBeans,其项目主页是:https://github.com/frakbot/JumpingBeans
JumpingBeans将一个普通的Android TextView中显示的字符串可以做到波浪式跳动。JumpingBeans使用起来简单,
仅仅在Android的Java代码中将一个普通Android TextView加载即可:
注意:需要jdk1.7
1 package zzw.demo; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.widget.TextView; 6 import net.frakbot.jumpingbeans.JumpingBeans; 7 8 public class MainActivity extends Activity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(R.layout.activity_main); 14 15 // 增加跳动的点 16 final TextView textView1 = (TextView) findViewById(R.id.textView1); 17 JumpingBeans jumpingBeans1 = JumpingBeans.with(textView1) 18 .appendJumpingDots() 19 .build(); 20 21 // 从第一个字符串到最后一个字符串波浪式循环跳动, textView2.getText().length()不能为0 22 final TextView textView2 = (TextView) findViewById(R.id.textView2); 23 JumpingBeans jumpingBeans2 = JumpingBeans.with(textView2) 24 .makeTextJump(0, textView2.getText().length()) 25 .setIsWave(true) 26 .setLoopDuration(3000) 27 .build(); 28 } 29 }
xml:
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context="com.zzw.testjumpingbeans.MainActivity" > 6 7 <TextView 8 android:id="@+id/textView1" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:layout_alignParentTop="true" 12 android:layout_centerHorizontal="true" 13 android:text="http://www.cnblogs.com/zzw1994" 14 android:textColor="@android:color/holo_blue_light" 15 android:textSize="20sp" /> 16 17 <TextView 18 android:id="@+id/textView2" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:layout_centerInParent="true" 22 android:text="http://www.cnblogs.com/zzw1994" 23 android:textColor="@android:color/holo_red_light" 24 android:textSize="20sp" /> 25 26 </RelativeLayout>