Android将动画应用于按钮背景

标签 android animation button drawable

我有一个按钮,当前在点击时为其分配了一个动画:

Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        v.startAnimation(animRotate);
}
});

这是一个 XML 格式的按钮示例:

<Button
    android:id="@+id/btn"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:text="@string/btnText"
    android:textColor="#ffffff"
    android:textSize="18dp"
    android:padding="12dp"
    android:drawableTop="@drawable/btnIcon"
    android:layout_weight="1" />

动画效果很好,但是在按钮本身上有一个文本值和一个可绘制值,我希望能够定位可绘制对象并仅对其进行动画处理。我在网上搜索过,所有内容似乎都是通过对象的 ID 来定位对象,没有任何背景/可绘制选择。

欢迎任何反馈,即使只是告诉我无法完成也是如此。

非常感谢。

最佳答案

您可能想要使用 TextViewButton 创建一个 FrameLayout 并只为 Button 设置动画。

关于Android将动画应用于按钮背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11037237/

相关文章:

android - 从 Robotium 测试用例中的错误线程异常调用

Android Studio 实时模板不工作

Javascript:为什么我的 javascript 不运行两个动画?

javascript - 在 for 循环中更改 SVG 行的 strokeDashoffset

flutter - 如何更改 OutlinedButton 的边框颜色

android - 如何选中和取消选中 CheckBox?

android - Logcat 首先显示 “The specified child already has a parent. You must call removeView() on the child' 的父级。”在我的第二个警报对话框中

javascript - 如何在加载之前不显示内容的情况下使用 jQuery 动画化幻灯片?

asp.net - 在 .net 中输入 key 和多个提交按钮

c# - 如何设置 anchar 以删除按钮之间的空间