В Activity у меня есть три вида (среди прочих): TextView, ImageView и LinearLayout - последний я называю controlsView
.Существует метод (назовите его toggleControls()
, чтобы переключить видимость controlsView
с анимацией. Анимация довольно проста и создается при каждом вызове метода, например:
private void toggleControls () {
if (controlsView.getAnimation () != null) {
return; // already animating
}
if (controlsView.getVisibility () == View.GONE) {
Animation animation = new ScaleAnimation (1, 1, 0, 1);
animation.setAnimationListener (new AnimationListener () {
public void onAnimationEnd (Animation animation) { controlsView.setAnimation (null); }
public void onAnimationRepeat (Animation animation) {}
public void onAnimationStart (Animation animation) { controlsView.setVisibility (View.VISIBLE); }
});
animation.setDuration (500);
controlsView.setAnimation (animation);
animation.startNow ();
} else {
// hide
Animation animation = new ScaleAnimation (1, 1, 1, 0);
animation.setAnimationListener (new AnimationListener () {
public void onAnimationEnd (Animation animation) { controlsView.setAnimation (null); controlsView.setVisibility (View.GONE); }
public void onAnimationRepeat (Animation animation) {}
public void onAnimationStart (Animation animation) {}
});
animation.setDuration (500);
controlsView.setAnimation (animation);
animation.startNow ();
}
}
ThisКажется, работает нормально, когда вызывается после прикосновения к TextView, но когда я вызываю его после прикосновения к ImageView, я никогда не вижу воспроизведение анимации. Вместо этого, состояние представления (как отображается) не меняется ... доЯ касаюсь где-нибудь на экране, и в этот момент controlsView
все время появляется или исчезает (это BTW на планшете Xoom под управлением Android 3.0.1.)
Для полноты картины,слегка упрощенный XML для представлений, по которым щелкают:
<TextView android:id="@+id/first"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:onClick="pressedFirst" android:clickable="true"
android:text="xxxxxxxxxxxxxxxxxxxxxx"></TextView>
<ImageView android:id="@+id/second"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:onClick="pressedSecond" android:clickable="true"
android:src="@drawable/something"></ImageView>
... и для controlsView:
<LinearLayout android:id="@+id/controls"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:visibility="visible" android:orientation="horizontal">
<Button android:id="@+id/importantButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:onClick="pressedFilterButton" android:text="Important"></Button>
</LinearLayout>
Функции, указанные в приведенном выше XML, просто вызывают toggleControls()
метод.
Я подозреваю, что я неправильно понимаю кое-что фундаментальное здесь. Может, кто-нибудь даст мне подсказку, пожалуйста?