将afollestad MaterialDialog放在按钮下方

时间:2016-02-05 09:03:02

标签: android alertdialog popupwindow

是否可以选择将https://github.com/afollestad/material-dialogs放在按钮下方,就像我附加的模拟一样。

或者是否有其他库可以满足我的要求。

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要抓住点击后的用户界面的位置,即过滤器图标 ImageView。你必须使用

getLocationOnScreen() API and PopUpWindow component.

这是用于膨胀FilterUI的示例代码

    text_click=(TextView)findViewById(R.id.text_click);

          text_click.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  int[] locationOfView = new int[2];
                  text_click.getLocationOnScreen(locationOfView);
                  final View mView = inflater.inflate(R.layout.activity_map_view, null, false);
                  final PopupWindow popUp = new PopupWindow(mView, 500, 500, false);
                  popUp.setTouchable(true);
                  popUp.setFocusable(true);
                  popUp.setOutsideTouchable(true);
popUp.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext,android.R.color.transparent)));
                  popUp.showAtLocation(mView, Gravity.NO_GRAVITY, locationOfView[0], (locationOfView[1]+ text_click.getHeight()));
              }
          });