在android中添加视图时添加延迟

发布于 2025-01-05 02:43:30 字数 1993 浏览 0 评论 0原文

我有一个简单的动画附加到我正在创建的动态文本视图,但我想要的是在添加它们时添加延迟。请指导我该怎么做。

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明月夜 2025-01-12 02:43:30

用这个

 new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            //write your code here...
        }
    }, delay_time);

use this

 new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            //write your code here...
        }
    }, delay_time);
别想她 2025-01-12 02:43:30

试试这个...

 for(int k =0; k < 5; k++){
   //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++;
             new Handler().postDelayed(new Runnable() {
                    public void run() {

                    }
                }, 2000);
}

try this...

 for(int k =0; k < 5; k++){
   //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++;
             new Handler().postDelayed(new Runnable() {
                    public void run() {

                    }
                }, 2000);
}
梦幻的心爱 2025-01-12 02:43:30

尝试AysncTask。这是出于同样的原因。

Try AysncTask. It is meant for the same cause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文