Implement a TextView with an animation in its left side.
来源:互联网 发布:淘宝中年套裙 编辑:程序博客网 时间:2024/06/07 05:26
In my case, I want to write a TextView with an animation in its left side.
ImageView + TextView could work but it’s not frugal enough.
TextView with drawableLeft would be the best option.
<TextView … … android:drawablePadding=”10dip” android:drawableLeft=”@drawable/loadingicon” />
But above implementation just show a icon in the left of TextView, not an animation.
How to show an animation instead of a icon?
Assume you have 4 pictures which would be an animation if display them one after one. Then define animation xml in res/anim folder in your project.
loading_animation.xml:
<animation-list xmlns:android=”http://schemas.android.com/apk/res/android” android:oneshot=”false” > <item android:drawable=”@drawable/loading_1″ android:duration=”500″> </item> <item android:drawable=”@drawable/loading_2″ android:duration=”500″> </item> <item android:drawable=”@drawable/loading_3″ android:duration=”500″> </item></animation-list>
“android:oneshot” determines whether or not play the animation just once.
“android:duration” determines the duration of pictures switching.
Then in layout xml, use above animation like this:
<TextView … … android:drawablePadding=”10dip” android:drawableLeft=”@anim/loading_animation” />
Bingo? no, no, no, the animation can not switching yet.
You need to do more.
In java/Activity code, you must get the animation drawable and start it.
Drawable[] draws = locateAreaTextView.getCompoundDrawables();if (draws != null && draws.length > 0 && draws[0] instanceof AnimationDrawable) { loadingAnimation = (AnimationDrawable) draws[0]; loadingAnimation.start();}
In above, we get index 0 of the drawable array since drawableLeft is in 0 position of the array.
Now, the animation works. But there is one more trap.
If you put above codes in onCreate() of Activity, draws will be a [null, null, null, null] array.
You must put it in onResumse() of Activity.
- Implement a TextView with an animation in its left side.
- “The left-hand side of an assignment must be a variable” problem with charAt
- ANR in an IntentService with its own process
- I did an SDK update last night and it moved adb.exe. In its place it left a file called "adb_has_mov
- The left-hand side of an assignment must be a variable
- The left-hand side of an assignment must be a variable
- The left-hand side of an assignment must be a variable
- The left-hand side of an assignment must be a variable
- The left-hand side of an assignment must be a variable
- Misleading error message in PowerShell script: "Invalid assignment expression. The left hand side of an assignment operator need
- js中莫名奇妙的报The left-hand side of an assignment must be a variable错误
- left side of asn-op not an lvalue错误解决方法
- 严重: Servlet.service() for servlet [default] in context with path [/a] threw exception [edu.yale.its.
- Uncaught ReferenceError: Invalid left-hand side in assignment
- 118 js Uncaught ReferenceError: Invalid left-hand side in assignment
- 页面上报错:Invalid left-hand side in assignment
- ncaught ReferenceError: Invalid left-hand side expression in prefix operation
- Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
- Android之Handler用法总结
- switch 与 if else 效率分析与总结
- java 编译命令
- Unity 鼠标控制角色移动
- MFC:文本内容显示到ListBox,顺序不正确的解决方法
- Implement a TextView with an animation in its left side.
- Eclipse中遇到main方法不能运行 的情况
- 父亲的一个同学
- 再谈编译 ---《c++ primer》
- PostgreSql新手入门命令
- 用指针解决输入a和b两数字,按先后大小输出a和b
- Myeclipse IDE 如何把选中的字母进行大小写切换
- rabbitmq丢消息的处理方法
- Word2Vec的一些理解