2012-07-18 49 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中变得很小,然后按照问题中的建议将其增大为可能的“解决方案”/解决方法,但并不理想。