何为Android上的图像按钮设置setVisibility动画

何为Android上的图像按钮设置setVisibility动画

本文介绍了如何为Android上的图像按钮设置setVisibility动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局有listview和imagebutton:

I have a layout that has a listview and imagebutton:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="4px"
    android:background="@color/bgColor">

    <ImageButton
    android:id="@+id/imageButton"
    android:src="@drawable/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="0dp"
    android:layout_alignParentBottom="true"/>

    <ListView
    android:layout_above="@+id/imageButton"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    android:background = "@drawable/list_bg"
    android:divider="@drawable/grade"
    android:dividerHeight ="1px"
    android:cacheColorHint="#00000000"
    android:fastScrollEnabled= "true"
    android:scrollingCache ="true"
    android:smoothScrollbar="false"
    >
   </ListView>
</RelativeLayout>

根据用户选择我使用它来隐藏或显示图像按钮:

Based on user selection I am using this to hide or show the image button:

       ImageButton myButton = (ImageButton) findViewById(R.id.imageButton);
        myButton.setVisibility(View.GONE);

代码工作正常,但我想设置隐藏/显示过程的动画。如何实现这种效果?

The code is working fine, however I would like to animate the hide/show process. How do I achieve this effect?

推荐答案

是编写自己的动画侦听器并将其设置为动画如下:

Yes write your own animation listener and set it to the animation like this :

public class MyAnimationListener implements AnimationListener {
    private ImageButton mImgButton;

    public MyAnimationListener(ImageButton imgButton) {
        mImgButton = imgButton;
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        mImgButton.setVisibility(View.GONE);

    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto - generated method stub

    }

    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto - generated method stub

    }

}

然后将其设置为动画:

animation.setAnimationListener(new MyAnimationListener(myButton);

多数民众赞成。

这篇关于如何为Android上的图像按钮设置setVisibility动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:32