android button旋转,如何使Android Button的drawableLeft保持旋转?

我需要创建一个按钮,左边有一个图标,右边有一个文本。按下按钮后,我想看到在按钮的左图标处有一个旋转图像的动画。

我知道如何使用imageview旋转图像,但这对我当前的需求没有帮助。

我试着使用animationdrawable,但它也没有工作,没有动画,只有第一个png文件显示。然后,无论我使用背景或按钮的左边可绘制来运行animationDrawable,它都是相同的。代码如下: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:

android:oneshot="false">

// layout file, main.xml:

android:layout_width="fill_parent"

android:orientation="horizontal" android:padding="0dp"

android:layout_height="wrap_content" android:gravity="fill_horizontal" android:layout_margin="0dp">

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" />

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" />

最佳答案:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值