2010-08-12 5 views
1

나는 화면을 터치에 레이아웃을 애니메이션을 적용 할. 화면을 터치하면 레이아웃이있는 버튼이 화면 밖으로 나오고 다시 화면을 터치하면 레이아웃이 원래 위치의 화면에 나타납니다. 내가 프로그래밍을 통해 그것을 할 때안드로이드 : 번역 애니메이션은 처음 작동하지 두 번째

나는이 문제를 얻고있다. 그리고 XML을 통해 작동합니다. 프로그램에서

는 처음으로 작동하고 두 번째 시간에 작동하지 않는 approch. 심지어 나는 우리가 화면에서 클릭하면 그것은 애니메이션을 시작하는 모든 코드를 읽는 것을 관찰 그러나 그것은 애니메이션되지 않고 그 후 우리는 레이아웃에 추가 한 단추, 애니메이션 작품을 클릭합니다.

import android.app.Activity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Gravity; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.Window; 
import android.view.WindowManager; 
import android.view.View.OnClickListener; 
import android.view.View.OnTouchListener; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.view.animation.LayoutAnimationController; 
import android.view.animation.Animation.AnimationListener; 
import android.webkit.WebView; 
import android.widget.Button; 
import android.widget.FrameLayout; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.RelativeLayout.LayoutParams; 

public class BrowserDemo2 extends Activity implements AnimationListener, OnTouchListener, OnClickListener 
{ 
    WebView browser; 
    RelativeLayout parentLayout; 
    LinearLayout navigationBarOuterLinearLayout; 
    FrameLayout navigationBarInnerFrameLayout; 

    Button galleryButton; 
    Button creditsButton; 
    Button viewChangeButton; 

    byte animationType; 
    public static final byte ANIM_IN = 0; 
    public static final byte ANIM_OUT = 1; 
    boolean isNavigationBarVisible = true; 
    boolean isAnimationInProgress; 


    @Override 
    public void onCreate(Bundle icicle) 
    { 
    super.onCreate(icicle);  
    setFullscreen(); 

    setContentView(R.layout.main); 
    parentLayout = (RelativeLayout) findViewById(R.id.parent); 

    setNavigationBarLayout(); 
    parentLayout.addView(navigationBarOuterLinearLayout); 

    animationType = ANIM_OUT; 
    animController = new LayoutAnimationController(this, null); 

    } 

    public void setNavigationBarLayout() 
    { 
    navigationBarOuterLinearLayout = new LinearLayout(this); 
    LayoutParams navigationBarOuterLinearLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
    navigationBarOuterLinearLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    navigationBarOuterLinearLayout.setLayoutParams(navigationBarOuterLinearLayoutParams); 
    navigationBarOuterLinearLayout.setOrientation(LinearLayout.VERTICAL); 

    navigationBarInnerFrameLayout = new FrameLayout(this); 
    LayoutParams navigationBarInnerFrameLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
    navigationBarInnerFrameLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    navigationBarInnerFrameLayout.setLayoutParams(navigationBarInnerFrameLayoutParams); 
    navigationBarInnerFrameLayout.setBackgroundResource(R.drawable.uitabbar); 
    navigationBarInnerFrameLayout.setPadding(0, 5, 0, 0); 

    galleryButton = new Button(this); 
    galleryButton.setOnClickListener(this); 
    galleryButton.setText("Gallery"); 
    FrameLayout.LayoutParams galleryButtonParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.LEFT); 
    galleryButton.setLayoutParams(galleryButtonParams); 

    creditsButton = new Button(this); 
    creditsButton.setOnClickListener(this); 
    creditsButton.setText("Credits"); 
    FrameLayout.LayoutParams creditsButtonParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); 
    creditsButton.setLayoutParams(creditsButtonParams); 

    viewChangeButton = new Button(this); 
    viewChangeButton.setOnClickListener(this); 
    viewChangeButton.setText("Chnage View"); 
    FrameLayout.LayoutParams viewChangeButtonParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT); 
    viewChangeButton.setLayoutParams(viewChangeButtonParams); 

    navigationBarInnerFrameLayout.addView(galleryButton); 
    navigationBarInnerFrameLayout.addView(creditsButton); 
    navigationBarInnerFrameLayout.addView(viewChangeButton); 

    navigationBarOuterLinearLayout.addView(navigationBarInnerFrameLayout); 
    } 

    public void setFullscreen() 
    { 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
     WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    }  

    public void setAnimations() 
    { 
    switch(animationType) 
    { 
     case ANIM_IN: 
     { 
     isAnimationInProgress = true; 
     navigationBarOuterLinearLayout.setVisibility(View.VISIBLE);  
     animateLayout(R.anim.lower_navigation_bar_in, navigationBarOuterLinearLayout); 
//  parentLayout.requestFocus(); 
//  parentLayout.requestFocusFromTouch(); 
//  parentLayout.requestLayout(); 
     break; 
     } 
     case ANIM_OUT: 
     { 
     isAnimationInProgress = true; 
     animateLayout(R.anim.lower_navigation_bar_out, navigationBarOuterLinearLayout); 
     break; 
     } 
    } 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) 
    { 
    if(event.getAction() == MotionEvent.ACTION_UP) 
    { 
     Log.v("onTouch", "in touch realease.."); 
     setAnimations(); 
    } 
    return true;  
    } 



    Animation layoutAnimation; 
    LayoutAnimationController animController; 
    public void animateLayout(int type, LinearLayout layout) 
    { 
    layoutAnimation = AnimationUtils.loadAnimation(this, type); 
    layoutAnimation.setAnimationListener(this); 
    animController.setAnimation(layoutAnimation); 
    layout.setLayoutAnimation(animController); 
    layout.startLayoutAnimation(); 
    } 

    @Override 
    public void onAnimationEnd(Animation animation) 
    { 
    if(animationType == ANIM_OUT && isNavigationBarVisible) 
    { 
     animationType = ANIM_IN; 
     isNavigationBarVisible = false; 
     navigationBarOuterLinearLayout.setVisibility(View.INVISIBLE); 
    } 
    else 
    { 
     animationType = ANIM_OUT; 
     isNavigationBarVisible = true;  
    } 
    isAnimationInProgress = false; 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) 
    { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public void onAnimationStart(Animation animation) 
    { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public boolean onTouch(View v, MotionEvent event) 
    { 
    return false; 
    } 

    @Override 
    public void onClick(View v) 
    { 
    // TODO Auto-generated method stub 
    } 

답변

1

내가 인정하고 싶은 것보다 좀 더 시간이 매우 비슷한 문제로 고생 : 여기

는 코드입니다. 저는 두 가지 견해를 같이 움직이고 교차하고 있습니다. 상태에 따라 앞뒤로. 한 방향은 작동하지만 다른 방향은 작동하지 않았습니다. 하나는 키보드 동작에 의해 활성화되고 다른 하나는 버튼 누름에 의해 활성화됩니다. 하나는 텍스트 입력이 있었기 때문에

, 나는 가시성을 설정 View.GONE를 사용하여 갔다. 나는 이것이 문제가 있었던 곳이라고 생각한다. 나는 애니메이션이 완료 될 때까지 뷰가 View.VISIBLE으로 설정되지 않았다고 믿는다. (어쨌든 View.GONE을 한 시점에서). 이것을 확인할 수는 없지만 모든 setVisibility() 호출을 제거하고 순수한 알파 변경을 수행하면 모든 것이 올바르게 작동하기 시작했습니다.

나는 또한 setFillAfter()과 같은 것을 사용하지 않았지만보기의 그려진 부분 만 움직일 수 있었고 실행 가능 (클릭 가능) 영역이 아니기 때문에 위치를 직접 계산했습니다.

+0

나는 또한 내 코드에서 View.GONE를 제거했습니다. 그럼에도 불구하고, 나는 그것을 무의미하게 만든 후에 문법적으로 레이아웃의 높이를 바꾸고있다. 잘 작동합니다. 힌트를 주셔서 감사합니다 :) – Aakanksha

관련 문제