我有一个RelativeLayout,其中两个LinearLayouts和一个TextView(所有3个是子节点)共享相同的空间,这意味着只有一个View是可见的,而其他两个View在任何给定点都是Gone。在应用程序启动时,TextView是Visible View。我有一个按钮,它启动一个动画,使TextView淡出,一个LinearLayout淡入。另一个按钮用于另一个LinearLayout。
逻辑如下:
按钮按下 - > TextView淡出 - > LinearLayout设置为Visible - > LinearLayout淡入。
后退按钮 - > LinearLayout淡出 - > OnAnimationEnd LinearLayout可见性消失 - > TextView淡入
只要上述交互使用相同的按钮(对于相同的LinearLayout),这种方法就完美无缺。按下另一个LinearLayout按钮后,在正确的LinearLayout淡入之前TextView的淡出期间会短暂显示另一个LinearLayout。按下后退按钮时会发生同样的事情:另一个LinearLayout会在淡出和淡出之间短暂显示淡出。
有什么想法吗?
fadeOut = AnimationUtils.loadAnimation......
fadeIn = AnimationsUtils......
fadeOut.setAnimationListener(this)
......
.....
public void buttonOnClick(View v) {
int id = v.getId();
switch(id) {
case R.id.get_started:
viewState = SIGNUP_STATE;
toggleWelcomeViews(HIDE);
toggleSignupViews(SHOW);
break;
case R.id.already_have_account:
viewState = LOGIN_STATE;
toggleWelcomeViews(HIDE);
toggleLoginViews(SHOW);
break;
}
......
....
public void toggleSignupViews(int flag) {
/*
int action = (flag == SHOW) ? View.VISIBLE : View.GONE;
signupForm.setVisibility(action);
whyPhoneLink.setVisibility(action);
submitButton.setVisibility(action);
*/
if (flag == SHOW) {
if (NetworkConfig.debug) Log.i(LOG_TAG, "fade in signup views");
signupForm.setVisibility(View.VISIBLE);
whyPhoneLink.setVisibility(View.VISIBLE);
submitButton.setVisibility(View.VISIBLE);
submitButton.setClickable(true);
signupForm.startAnimation(fadeIn);
whyPhoneLink.startAnimation(fadeIn);
submitButton.startAnimation(fadeIn);
} else {
if (NetworkConfig.debug) Log.i(LOG_TAG, "fade out signup views");
signupForm.startAnimation(fadeOut);
whyPhoneLink.startAnimation(fadeOut);
submitButton.startAnimation(fadeOut);
signupForm.setVisibility(View.INVISIBLE);
whyPhoneLink.setVisibility(View.INVISIBLE);
submitButton.setVisibility(View.INVISIBLE);
submitButton.setClickable(false);
}
}
......
......
public void onBackPressed() {
switch(viewState){
case WELCOME_STATE:
// exit app..
super.onBackPressed();
break;
case SIGNUP_STATE:
// hide signup views and show welcome views
viewState = WELCOME_STATE;
leavingState = SIGNUP_STATE;
toggleSignupViews(HIDE);
toggleWelcomeViews(SHOW);
break;
case LOGIN_STATE:
// hide login views and show welcome views
viewState = WELCOME_STATE;
leavingState = LOGIN_STATE;
toggleLoginViews(HIDE);
toggleWelcomeViews(SHOW);
break;
}
}
@Override
public void onAnimationEnd(Animation animation) {
if (NetworkConfig.debug) Log.i(LOG_TAG, "animation ended");
if (leavingState == SIGNUP_STATE) {
signupForm.setVisibility(View.INVISIBLE);
whyPhoneLink.setVisibility(View.INVISIBLE);
submitButton.setVisibility(View.INVISIBLE);
submitButton.setClickable(false);
} else if (leavingState == LOGIN_STATE) {
loginForm.setVisibility(View.INVISIBLE);
forgotPassword.setVisibility(View.INVISIBLE);
submitButton.setVisibility(View.INVISIBLE);
submitButton.setClickable(false);
}
}
所有缺失的切换...()函数的逻辑与上面的相同。我已经尝试将View.GONE代码放在onAnimationEnd中,但结果是一样的(错误仍然存在)。