我想要实现这一点:
-
一个活动以没有 ClickListener 的方式开始,并且有四个带有白色背景的文本视图
我想更改textview 1 的颜色为蓝色。等待 2 秒,然后将其改回白色,并将 textview 2 更改为蓝色。等待 2 秒,然后将其更改回白色...依此类推,直到我将 textview 4 更改为蓝色并返回白色。
-
完成后,我想添加 ClickListener 并等待用户输入。
我怎样才能实现这个目标?我是 Android 新手,但了解一些细节。
This I want I want to achieve:
-
An activity starts with no ClickListener and has four textviews all with white background
-
I want to change the color of textview 1 to blue. Wait for 2 seconds and then change it back to white and change the textview 2 to blue. wait for 2 seconds and then change it back to white... so on till i have turned textview 4 to blue and back to white.
-
Once that is complete, I want to add the ClickListener and wait for user input.
How can I achieve this? I am new to Android but understands bits and pieces.
发布评论
评论(3)
您可以通过创建 动画 序列来实现此目的,无论是XML 或 Java 代码,并按顺序触发它们。您需要使用 LayoutAnimationController 定义动画序列,位于动画结束时,您可以添加ClickListener。
Developer Life 有一个帮助您开始使用动画的好教程。 Jeff 有一个由两部分组成的动画教程系列 - 部分1,第 2 部分 。
希望这有帮助,
印地弗罗兹
You can achieve this by creating Animation sequences, in either XML or Java code, and triggering them in sequence. You will need to define a animation sequence with LayoutAnimationController, at the end of the animation, you can add the ClickListener.
Developer Life has a good tutorial to get you started on animations. Jeff has a two-part tutorial series on animations - part 1, part 2.
Hope this helps,
indyfromoz
无需为此创建线程或动画。
解决方案非常简单:使用 Handler.postDelayed() 或 Handler.sendMessageDelayed():
http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long)
http://developer.android.com/reference /android/os/Handler.html#sendMessageDelayed(android.os.Message, long)
为了实现稳健,请确保至少通过 Activity.onDestroy() 删除任何待处理的消息(或者如果您正在发布消息)。在 Activity.onStart() 中删除它们,在 Activity.onStop() 中删除它们;如果在 Activity.onResume() 中发布,则在 Activity.onPause() 中删除。)
There is no need to create a thread for this, or animations.
The solution is really simple: use Handler.postDelayed() or Handler.sendMessageDelayed():
http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable, long)
http://developer.android.com/reference/android/os/Handler.html#sendMessageDelayed(android.os.Message, long)
For a robust implementation, be sure to remove any pending messages at least by Activity.onDestroy(). (Or if you are posting them in Activity.onStart(), remove them in Activity.onStop(); if posting in Activity.onResume(), remove in Activity.onPause().)
我有一个用于此任务的示例,但是通过带有handleMessage
kayout的线程:
祝你好运,
I have one sample for this task but by thread with handleMessage
kayout:
Good luck,