我已經搜索了周圍的堆棧溢出,但仍然遇到了這個問題。根據按鈕繪製動畫
我想在我的應用程序上顯示一個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