我有一个带有列表视图和图像按钮的布局:
<?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>
根据用户选择,我使用它来隐藏或显示图像按钮:
ImageButton myButton = (ImageButton) findViewById(R.id.imageButton);
myButton.setVisibility(View.GONE);
代码工作正常,但是我想为隐藏/显示过程设置动画。我怎样才能达到这个效果呢?
您可以使用系统动画淡入和淡出。
Animation animFadeOut = AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out);
Animation animFadeIn = AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in);
myButton.setAnimation(animFadeOut)
//if necessary then call:
myButton.setVisibility(View.GONE);
那应该有效
如果你想制作自己的动画:查看 Android 资源 http://developer.android.com/guide/topics/resources/animation-resource.html
and 这是一个非常好的教程 http://developerlife.com/tutorials/?p=343用于动画。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)