【问题标题】:Android:- change the text on buttons sequentially using animationAndroid:- 使用动画顺序更改按钮上的文本
【发布时间】:2013-01-03 03:06:35
【问题描述】:

我在 android 中有一系列按钮,我需要按顺序更改这些按钮的文本(慢慢地一个一个地)我怎样才能做到这一点?我不能在这里应用任何动画?

【问题讨论】:

  • 你可以使用处理程序......

标签: android animation button text


【解决方案1】:

真的很难说清楚 您想在此处执行的操作,但一种选择是使用TimerTask 您可以按您想要的任何间隔重复更改按钮的文本。您可以使用 for loop 来遍历按钮

【讨论】:

    【解决方案2】:
    Handler myHandler = new Handler(); 
    

    // 你的按钮是这样的

    int[] ButtonArray = {R.id.button1,R.id.button2.....};
    String[] stringArray = {"Hi","Hello","oi"....};
    
     // get all the button
     private Button[] myButtons=new Button[buttonArray.length];
    
     for(int i = 0; i < buttonArray.length ; i++){
          myButtons[i] = (Button) findViewById(mAlphabetsId[i]); 
    
     }
    

    //处理重复性任务的处理程序

    ....... 开始重复性的任务

    counterValue = 0;
    Size =buttonArray.length; //Number of buttons
     myHandler.postDelayed(mMyRunnable, speed); 
    

    .......................

       private Runnable mMyRunnable = new Runnable()
    {
    
        public void run()
        { 
            if(counterValue<Size){  
               myButtons[counterValue].setText(stringArray[CounterValue]);    
              myHandler.postDelayed(mMyRunnable, 1000);  //Call again with 1 sec delay
             counterValue++;
            }else{
                 myHandler.removeCallbacks(mMyRunnable);
                 counterValue=0;    
            }
    
        }
    };
    

    此代码可能包含错误,因为我很着急。先试试看。

    如果您遇到问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 2016-01-13
      • 2018-02-18
      • 2021-03-24
      相关资源
      最近更新 更多