2012-07-18 48 views
0

於是我開始了我的活動,然後需要明確的ImageButton開始動畫

setContentView(R.layout.myxmllayoutfile); 

一切都很好過,但我想從一無所有(即1%),使我的ImageButton突然增長(規模)。然而,佈局已經顯示按鈕,所以它突然消失,然後增長回來,而不是從無增長。

我有一些替代品,但有沒有一個真正的解決方案?: 1.從屏幕外飛行動畫的imagebutton? ;或 2.使它在xml中很小,然後增長它,然後如果需要更改可點擊區域?或 3.有沒有更好的解決方案?

UPDATE: 作爲建議我嘗試:

<ImageButton 
android:id="@+id/spinner" 
android:scaleType="fitXY" 
android:layout_width="120dp" 
android:layout_height="120dp" 
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" 
android:background="@drawable/clear" 
android:orientation="horizontal" 
android:visibility="invisible" 
android:src="@drawable/spin" 
/> 

,在我的java:

scaleView.startAnimation(scanimation); 
ImageButton spinnerbutton=(ImageButton)findViewById(R.id.spinner); 
spinnerbutton.setVisibility(View.VISIBLE); 

,但它仍然是可見它縮小到1%,那麼增長之前!建議歡迎。

UPDATE2:

什麼都沒有用編輯下面的代碼更改:

public void growit() { 
final ImageView scaleView = (ImageView) findViewById(R.id.spinner); 
Animation scanimation = AnimationUtils.loadAnimation(this, R.anim.throbbing2); 
scanimation.setFillAfter(true); 
scanimation.setAnimationListener(new Animation.AnimationListener() { 
public void onAnimationStart(Animation a) { Log.e("growit", "---- animation start listener called"); 
scaleView.setVisibility(View.VISIBLE); 
} 
public void onAnimationRepeat(Animation a) { 
} 
public void onAnimationEnd(Animation a) { 
} 
}); 
scaleView.startAnimation(scanimation); 


} 
+0

在xml代碼中隱藏圖像按鈕。 加入android:visibility =「gone」或「invisible」如果它適合您的情況 – Maxim 2012-07-18 10:57:31

+0

android:visibility =「invisible」已經。我會去嘗試,因爲我沒有任何損失。 – 2012-07-19 05:46:08

回答

1

製作的ImageButton隱藏。 然後在你的動畫集動畫監聽器,並在啓動動畫回調方法設置按鈕可見

UPDATE:

 Animation animation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f); 
     animation.setAnimationListener(new AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 
       mImageButton.setVisibility(View.VISIBLE); 
      } 
      @Override 
      public void onAnimationRepeat(Animation animation) { } 
      @Override 
      public void onAnimationEnd(Animation animation) { } 
     }); 
     mImageButton.startAnimation(animation); 
+0

請參閱UPDATE部分中的示例 – Maxim 2012-07-18 08:07:58

+0

請參閱我的更新1和2.失敗! :( – 2012-07-18 09:04:59

+0

你確定imagebutton最初是隱藏的嗎?根據你的代碼,它是可見的 – Maxim 2012-07-18 10:54:59

0

沒有永久性的解決方案。只是使用了一種解決方法,使其在xml中變得很小,然後按照問題中的建議將其增大爲可能的「解決方案」/解決方法,但並不理想。