在android中添加视图时添加延迟
我有一个简单的动画附加到我正在创建的动态文本视图,但我想要的是在添加它们时添加延迟。请指导我该怎么做。
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
final HorizontalScrollView hsv = new HorizontalScrollView(TestViewActivity.this);
LinearLayout lhsv = new LinearLayout(TestViewActivity.this);
Animation a1 = new AlphaAnimation(0.00f, 1.00f);
a1.setDuration(350);
a1.setFillAfter(true);
for(int k =0; k < 5; k++){
// may be some handler here but how ?
TextView tv = new TextView(TestViewActivity.this);
tv.setText("Text");
tv.setTextSize(42);
tv.setPadding(10, 0, 10, 0);
tv.setVisibility(View.INVISIBLE);
tv.clearAnimation();
tv.startAnimation(a1);
lhsv.addView(tv, k);
}
hsv.addView(lhsv);
ll.addView(hsv);
谢谢
根据建议,我已经尝试过这个方法,它可以工作,但是所有视图都放在一起,我想要的是一个视图输入然后有点延迟,然后另一个视图输入等等......这是代码。
final Handler handler = new Handler();
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
final HorizontalScrollView hsv = new HorizontalScrollView(TestViewActivity.this);
final LinearLayout lhsv = new LinearLayout(TestViewActivity.this);
final Animation a1 = new AlphaAnimation(0.00f, 1.00f);
a1.setDuration(350);
a1.setFillAfter(true);
for(int k =0; k < 5; k++){
new Handler().postDelayed(new Runnable() {
public void run() {
//write your code here...
final TextView tv = new TextView(TestViewActivity.this);
tv.setText("Text");
tv.setTextSize(42);
tv.setPadding(10, 0, 10, 0);
tv.setVisibility(View.INVISIBLE);
tv.clearAnimation();
tv.startAnimation(a1);
lhsv.addView(tv, temp);
temp++;
}
}, 2000);
}
hsv.addView(lhsv);
ll.addView(hsv);
I have a simple animation attached to dynamic textview that i am creating but what i want is to add delay while adding them. Please guide me how to do that.
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
final HorizontalScrollView hsv = new HorizontalScrollView(TestViewActivity.this);
LinearLayout lhsv = new LinearLayout(TestViewActivity.this);
Animation a1 = new AlphaAnimation(0.00f, 1.00f);
a1.setDuration(350);
a1.setFillAfter(true);
for(int k =0; k < 5; k++){
// may be some handler here but how ?
TextView tv = new TextView(TestViewActivity.this);
tv.setText("Text");
tv.setTextSize(42);
tv.setPadding(10, 0, 10, 0);
tv.setVisibility(View.INVISIBLE);
tv.clearAnimation();
tv.startAnimation(a1);
lhsv.addView(tv, k);
}
hsv.addView(lhsv);
ll.addView(hsv);
Thanks
Based on suggestion i have tried this it works, but all view come all together, what i want is that one view enter then bit of delay then another view enter and so on...this is the code.
final Handler handler = new Handler();
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
final HorizontalScrollView hsv = new HorizontalScrollView(TestViewActivity.this);
final LinearLayout lhsv = new LinearLayout(TestViewActivity.this);
final Animation a1 = new AlphaAnimation(0.00f, 1.00f);
a1.setDuration(350);
a1.setFillAfter(true);
for(int k =0; k < 5; k++){
new Handler().postDelayed(new Runnable() {
public void run() {
//write your code here...
final TextView tv = new TextView(TestViewActivity.this);
tv.setText("Text");
tv.setTextSize(42);
tv.setPadding(10, 0, 10, 0);
tv.setVisibility(View.INVISIBLE);
tv.clearAnimation();
tv.startAnimation(a1);
lhsv.addView(tv, temp);
temp++;
}
}, 2000);
}
hsv.addView(lhsv);
ll.addView(hsv);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用这个
use this
试试这个...
try this...
尝试
AysncTask
。这是出于同样的原因。Try
AysncTask
. It is meant for the same cause.