按钮进入PopupView。

时间:2012-12-06 18:31:49

标签: android android-animation android-button

我的PopupView中有一个LinearLayout,还有一个进入此LinearLayout的按钮。此按钮的事件监听器正常工作,但按下(突出显示)的动画未启动。我做错了什么?请,gelp!

        public class PopupView extends View 
{
    private PopupWindow popUp;
    private Button buttonOk;
    private OnClickListener onClick;
    private LayoutParams params;
    private int popUpWidth = 0;
    private int popUpHeight = 0;
    private int popUpX, popUpY;

    public PopupView(Context context, View parent)
    {
        super(context);
        popUp = new PopupWindow(context);
        popUpLayout = new LinearLayout(context);
        buttonOk = new Button(context);
        buttonOk.setText("OK");
        buttonOk.setId(1);

        params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        popUpLayout.setOrientation(LinearLayout.VERTICAL);
        popUp.setContentView(popUpLayout);

        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);

        popUpLayout.removeAllViews();
        popUpLayout.addView(buttonOk, params);


        popUpWidth = 200;
        popUpHeight = 400;

        popUpX = 300;
        popUpY = 300;

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

1 个答案:

答案 0 :(得分:0)

默认情况下,PopupView不可聚焦。需要调用方法popup.setFocusable(true)。谢谢大家!