2012-12-02 4 views
1

나는 내 PopupView에 LinearLayout을 가지고 있고이 LinearLayout에 버튼을 가지고있다. 이 버튼의 이벤트 리스너는 올바르게 작동하지만 누르는 (강조 표시) 애니메이션이 시작되지 않습니다. 내가 뭘 잘못 했니? 제발, 제발!PopupView로 안드로이드 버튼 애니메이션

public class PopupView extends View 
{ 
    private PopupWindow popUp; 
    private LinearLayout popUpLayout; 
    private TextView titleTextView; 
    private TextView lengthTextView; 
    private TextView heighTextView; 
    private TextView percentTextView; 
    private Button buttonOk; 
    private Button buttonDelete; 
    private EditText edTextLength, edTextHeight; 
    private OnClickListener onClick; 
    private LayoutParams params; 
    private int popUpWidth = 0; 
    private int popUpHeight = 0; 
    private int lastPopupped; 
    private boolean isCreated = false; 
    private int popUpX, popUpY; 

    public static final int POINT_MOVE = 1; 

    public PopupView(Context context) 
    { 
     super(context); 
     popUp = new PopupWindow(context); 
     popUpLayout = new LinearLayout(context); 
     titleTextView = new TextView(context); 
     lengthTextView = new TextView(context); 
     heighTextView = new TextView(context); 
     percentTextView = new TextView(context); 
     buttonOk = new Button(context); 
     buttonDelete = new Button(context); 
     titleTextView.setTextColor(Color.BLACK); 
     lengthTextView.setTextColor(Color.BLACK); 
     heighTextView.setTextColor(Color.BLACK); 
     percentTextView.setTextColor(Color.BLACK); 
     buttonOk.setText("OK"); 
     buttonOk.setId(1); 
     buttonDelete.setText("Delete"); 
     buttonDelete.setId(2); 

     params = new LayoutParams(LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT); 
     popUpLayout.setClickable(true); 
     popUpLayout.setOrientation(LinearLayout.VERTICAL); 

     popUp.setContentView(popUpLayout); 
    } 

    public void createPopup (View parent, int typeOfPopUp, DataContainer dContainer, int numOfPoint, int statusBar, 
      float scaleFactor, int scrollX, int scrollY) 
    { 
     switch (typeOfPopUp) 
     {  
     case 1: 
      titleTextView.setText("Ground Point # " + (1 + numOfPoint)); 
      lengthTextView.setText("Length = " + dContainer.groundPoints.get(numOfPoint).length); 
      heighTextView.setText("Heigh = " + dContainer.groundPoints.get(numOfPoint).heigh); 

      onClick = new OnClickListener() 
      { 
       public void onClick (View v) 
       { 
        switch (v.getId()) 
        { 
        case 1: 
         System.out.println("OK pressed!"); 
         break; 

        case 2: 

         break; 
        } 
       } 
      }; 

      buttonOk.setOnClickListener(onClick); 
      buttonOk.setFocusable(true); 
      buttonDelete.setOnClickListener(onClick); 

      popUpLayout.removeAllViews(); 
      popUpLayout.addView(titleTextView, params); 
      popUpLayout.addView(lengthTextView, params); 
      popUpLayout.addView(heighTextView, params); 
      buttonDelete.setEnabled(true); 
      popUpLayout.addView(buttonDelete, params); 
      popUpLayout.addView(buttonOk, params); 


      popUpWidth = (int)(titleTextView.getTextSize()/2 * 18); 
      popUpHeight = (int)(titleTextView.getTextSize() * 13); 

      popUpX = (int)((dContainer.groundPoints.get(numOfPoint).length) * scaleFactor - scrollX); 
      popUpY = (int)((dContainer.groundPoints.get(numOfPoint).heigh) * scaleFactor + statusBar - scrollY); 

      popUpX += statusBar; 
      popUpY += statusBar; 

      popUp.showAtLocation(parent, Gravity.NO_GRAVITY, popUpX, popUpY); 
      popUp.update(popUpX, popUpY, popUpWidth, popUpHeight); 

      lastPopupped = numOfPoint; 
      isCreated = true; 
      break; 
     } 
    } 

    public void removePopup() 
    { 
     if (isCreated) 
     { 
      popUp.dismiss(); 
     } 
    } 

    public void updatePopup (DataContainer dContainer, int statusBar, 
      float scaleFactor, int scrollX, int scrollY) 
    { 
     if (isCreated) 
     { 
      popUp.update((int)((dContainer.groundPoints.get(lastPopupped).length) * scaleFactor - scrollX), 
        (int)((dContainer.groundPoints.get(lastPopupped).heigh) * scaleFactor + statusBar - scrollY), 
        popUpWidth, popUpHeight); 
     } 
    } 

} 
+1

아무도 코드를 보지 않거나 "애니메이션"이 실제로 당신에게 의미하는 것이 무엇인지 아는 것이 아니라면 추측을 시작할 것입니다. –

+0

질문은 실제 내용입니다. 도와주세요! – NikitaDjigurda

답변

0

기본적으로 PopupView는 포커스가 없습니다. popup.setFocusable (true) 메서드를 호출해야합니다. 모두에게 감사드립니다!