我已经搜索了周围的堆栈溢出,但仍然遇到了这个问题。根据按钮绘制动画
我想在我的应用程序上显示一个Button
,使用AnimationDrawable
作为我的背景。我遵循了Android开发者页面(http://developer.android.com/guide/topics/graphics/drawable-animation.html)并能够获得动画效果。但是,我的按钮完全隐藏。用户仍然可以点击它,但背景动画可以隐藏它,就好像没有按钮一样。
我试过setAlpha
,但将它应用到我的'AnimationDrawable'模糊了我的Drawable
“电影胶卷”中的3张图像。此外,屏幕从黑色开始,需要很长时间才能逐渐达到设定的不透明度。它首先看到它是一个内存问题,但截至目前,我的应用程序只是一个Activity
与Button
导致另一个Activity
。
有谁知道如何让我的Button
出现在我的AnimationDrawable
之上?或者是否有人使用setAlpha
减慢动画速度?
这里是我的参考代码:
public class Main extends Activity {
Button start;
Intent intent= new Intent();
ImageView background;
AnimationDrawable animation;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
background= (ImageView) findViewById(R.id.imagehost);
background.setBackgroundResource(R.drawable.anim);
animation= (AnimationDrawable) background.getBackground();
start= (Button) findViewById(R.id.start);
start.setOnClickListener(new OnClickListener(){
...
} //end of onCreate
@Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
animation.start();
//animation.setAlpha(50); //doesn't help
}//end of onWindowFocusChanged
EDIT
布局XML(main.xml中)的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/start"
android:textSize="40sp" />
<ImageView
android:id="@+id/imagehost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="58dp" />
animationdrawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/bgnd1"
android:duration="600" />
<item android:drawable="@drawable/bgnd2"
android:duration="600" />
<item android:drawable="@drawable/bgnd3"
android:duration="600" />
</animation-list>
你能告诉我们你的布局xml吗? – caiocpricci2
是的,只是加了它们! – Bethany
为什么不把动画可绘制应用到按钮bg? – Leonidos