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

  • Home
  • SEARCH
  • 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 6801361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:05:27+00:00 2026-05-26T19:05:27+00:00

I need to create a button where there is a icon in the left

  • 0

I need to create a button where there is a icon in the left and a text in the right. After pressing the button, I want to see there is an animation of rotating image at the place of the left icon in the button.

I know how to rotate a image with ImageView, but it is not helpful to my current requirement.

I tried to use AnimationDrawable, but it did not work either, there is no animation but only the first png file shown. It is then same whatever I use the background or leftDrawable of the button to run the AnimationDrawable. The code is as below:

package com.example.layout;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;

public class TestLinearlayoutActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public void onStart() {
        super.onStart();

        Button locationTitleButton = (Button) findViewById(R.id.LocationTitleButton);
        //locationTitleButton.setBackgroundResource(R.drawable.loading);

        locationTitleButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.loading, 0, 0, 0);

        Drawable[] locationTitleButtonDrawables = locationTitleButton.getCompoundDrawables();
        AnimationDrawable animDrawable = (AnimationDrawable) locationTitleButtonDrawables[0];
        //AnimationDrawable animDrawable = (AnimationDrawable) locationTitleButton.getBackground();
        animDrawable.start();
    }
}

//loading.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">

    <item android:drawable="@drawable/loc1" android:duration="200" />
    <item android:drawable="@drawable/loc2" android:duration="200" />
    <item android:drawable="@drawable/loc3" android:duration="200" />
    <item android:drawable="@drawable/loc4" android:duration="200" />

</animation-list>

// layout file, main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="horizontal" android:padding="0dp"
    android:layout_height="wrap_content" android:gravity="fill_horizontal" android:layout_margin="0dp">

    <Button android:id="@+id/LocationTitleButton"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginRight="0dip"
        android:layout_gravity="center_vertical"
        android:gravity="center_vertical"
        android:layout_weight="1"
        android:ellipsize="end" 
        android:scrollHorizontally="true" 
        android:singleLine="true"
        android:text="Add location" 
        android:textStyle="bold" />

    <Button android:textColor="#FF000000" 
        android:layout_weight="0" 
        android:id="@+id/AddLocationButton" 
        android:text="Search" 
        android:gravity="center_vertical"
        android:layout_gravity="center_vertical" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_marginLeft="-8dp" />

</LinearLayout>
  • 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-26T19:05:28+00:00Added an answer on May 26, 2026 at 7:05 pm

    You can try using an AnimationDrawable.

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

Sidebar

Related Questions

I need to create a transparent button with image and text. I have a
I need to create a button that has the same style as ButtonSpec with
I have a situation where i need to create a left panel. My manager
Is there a way to create styles in PowerPoint VSTO to format text, something
I want to create a button with the same look and feel as the
Image comments: Icon should go centered in the red bit. The text should go
I need to create several combo boxes to represent enumeration values. I want the
I wanted to create a button that had an image and a textblock as
Hopefully this is an easy one... I need to create an Alert Me button
From within my web application (ASP.NET/C#) I would need to create a button that,

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.