如何在单击的视图附近显示自定义视图帮助框。

时间:2016-05-20 10:17:22

标签: android android-layout dialog android-custom-view

如何在android中实现这一点。https://www.google.com/design/spec/motion/choreography.html#choreography-creation此菜单从触摸点出现,将元素绑定到触摸点。

Error message in edittext comes in the bottom of the view

1 个答案:

答案 0 :(得分:1)

您可以使用PopupWindow然后使用popupWindow.showAsDropDown(theView)。

修改 以下是我的代码中的示例:

    LayoutInflater inflater = (LayoutInflater) TimeCheckActivity.this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.timecheck_popup,
            (ViewGroup) findViewById(R.id.popup_element));
    popupWindow = new PopupWindow(layout, 320, 160, true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setOutsideTouchable(true);

    radioButton[1].setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(times.size()>1) {
                popupText.setText(times.get(1).toString());
                popupWindow.showAsDropDown((View) radioButton[1]);

            }
            return true;
        }
    });

我也有xml布局,其中包含Textview(" popupText")。