0

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

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

1 回答 1

0

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

于 2012-12-08T22:54:22.647 回答