Position afollestad MaterialDialog below a button

2019-09-14 00:46发布

问题:

Is there an option to position https://github.com/afollestad/material-dialogs below a button as like the mock up I have attached .

Or is there any other library to fulfill my requirement.

回答1:

You need to catch the location of the clicked UI that is your Filter icon ImageView. You have to use the

getLocationOnScreen() API and PopUpWindow component.

This is the sample code for inflating the 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()));
              }
          });