Show toast widget underneath a view

后端 未结 6 1784
别那么骄傲
别那么骄傲 2020-11-29 12:05

For those who helped me out earlier regarding this project, thank you very much! My code no longer has any problems, and I made extra tweaks. Now that the app is actually ro

6条回答
  •  不知归路
    2020-11-29 12:49

    I would just like to add to solmaks answer.

    in positionToast:

        ...
        int toastHeight= toast.getView().getMeasuredHeight();
    
        // compute toast offsets
        ...
        int toastY = viewTop + (view.getHeight() - toastHeight) / 2 + offsetY;
    

    in onClick:

        positionToast(toast, view, getWindow(), 0, 0);  
    

    This seems to center the Toast perfectly in my view, no matter where the view is placed. There is an assumption in my code that the Toast will always be smaller than the view it is in.

提交回复
热议问题