Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:32:05+00:00 2026-05-27T15:32:05+00:00

In my main activity I have a button with the text Play. I want

  • 0

In my main activity I have a button with the text “Play”. I want the text to gradually grow and then gradually diminish in size. This should loop until the button is clicked. This effect should appear like a gentle glow.

So, I have tried using a Thread to accomplish this:

// Play Button Animation Thread
Thread playAnimation = new Thread() {
    public void run() {
        try {
            int textSize = 25;
            while (textSize <= 50) {
                playBtn.setTextSize(textSize);
                textSize += .10;
                sleep(100);
            }   
        } 

        catch (InterruptedException e) {
            e.printStackTrace();
        } 

        finally {

        }

    }
};

Then, I called the thread with:

playAnimation.start();

It isn’t working as I have it, but now I’m thinking there is probably a better way. Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:32:06+00:00Added an answer on May 27, 2026 at 3:32 pm

    There are a couple things wrong with the code you have written:

    1. You have declared your textSize variable as an int. Thus, your attempt to increment the value by 0.1 each iteration is futile because the value is cast back to an int after each operation, dropping off the value you just added (i.e. 25 += 0.1 -> 25.1, cast back to an int -> 25…lather, rinse repeat). So the value you are passing to setTextSize() never actually changes.
    2. Your code does not repeat. That loop will only run once until the value reaches 50, and then stop. You won’t get the back/forth effect you are going for.
    3. Your updates to the UI should ALWAYS occur on the main/rendering thread. You should never call any update methods (like setTextSize()) from any thread you have created. This can be solved by employing a Handler to manage the threading for you.

    If you want the entire button to animate, you can look at the animation framework like others have suggested. However, to automate just the text size, you are on the right path…we just need to tweak your code based on the points I mentioned above:

    Handler mHandler = new Handler();
    boolean mReverse = false;
    Runnable mUpdate = new Runnable() {
      @Override
      public void run() {
        float current = playBtn.getTextSize();
        if(mReverse) {
          current -= 0.1;
          playBtn.setTextSize(current);
          mReverse = (current <= 25);
        } else {
          current += 0.1;
          playBtn.setTextSize(current);
          mReverse = (current >= 50);
        }
    
        mHandler.postDelayed(mUpdate, 100);
      }
    }
    

    The Handler is created on the main thread, and all code inside the Runnable is executed on the main thread…so you may update the UI there. postDelayed() takes care of the wait delays so you don’t really need to create another thread at all. To start your animation, just call

    mHandler.postDelayed(mUpdate, 100);
    

    anywhere in your code. To stop the animation at any time, simply stop calling postDelayed after each iteration.

    HTH!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main activity and in this activity i have a button in
I have a design of activities like this I have one main activity and
I am using Button in main Activity. When i clicked this button it will
This is my code. So when button is clicked, I have two edit text
I have some main activity and clicking on a button it launches a custom
My Application have 5 activities(A1,A2,A3,A4,A5). Each activity have one text view and one button(B1,B2,B3,B4,B5).
I have a Main Activity, then a ListActivity to select an item to show,
I have an Activity ( Main ) which shows tabs like this: private void
I have work that needs to be done in this order: In main activity:
Have a problem. In my main Activity I have a ListView. And I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.