注:
本篇为转载原文:/zhangphil
Android 微光闪烁效果之更强Shimmer-android
实现Android Shimmer效果的解决方案不少,在前一篇中介绍了facebook自家的Android Shimmer效果实现(《Android Shimmer微光闪烁shimmer-android》文章链接地址:/zhangphil/article/details/49722913),本文介绍另外一种我个人觉得比facebook更好的一种实现效果:Shimmer-android(我个人建议使用这个开源库实现Android Shimmer效果,可定制效果更强)
Shimmer-android在github上的项目主页是:/RomainPiel/Shimmer-android
Shimmer-android干脆在Android TextView,Button的基础上重新写了ShimmerTextView和ShimmerButton。如果只是需要将一段文字实现Shimmer效果,直接使用ShimmerTextView即可。
Shimmer-android使用和前一篇facebook的使用类似,先写一个布局:
[html]view plaincopy<RelativeLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#9e9e9e"> <com.romainpiel.shimmer.ShimmerTextView android:id="@+id/shimmer_tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:text="ZhangPhil@CSDN" android:textColor="#757575" android:textSize="20sp"/> </RelativeLayout>
然后在Java代码中启动动画执行:
[java]view plaincopyimportandroid.app.Activity; importandroid.os.Bundle; importcom.romainpiel.shimmer.Shimmer; importcom.romainpiel.shimmer.ShimmerTextView; publicclassMainActivityextendsActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ShimmerTextViewtv=(ShimmerTextView)findViewById(R.id.shimmer_tv); Shimmershimmer=newShimmer(); shimmer.setDuration(2500); shimmer.start(tv); } }
start执行,cancel停止。
运行结果如图(其实是连续的动画效果,我只截了一张):