android - Popup showAtLocation is not working -


i'm using pop-window show text-view while clicking edit-text . pop-window not showing @ particular location ,it showing @ left top corner , here code ,what wrong in

    private void showpopup(context context,final linearlayout parent) {       layoutinflater layoutinflater = (layoutinflater)context       .getsystemservice(context.layout_inflater_service);     layout = layoutinflater.inflate(r.layout.popup,mainactivity.parent,true);     // creating popupwindow     final popupwindow popupwindow = new popupwindow(                layout,700,700);       popupwindow.setcontentview(layout);     popupwindow.setheight(500);       new runnable(){         @override         public void run() {              popupwindow.showatlocation(layout, gravity.center,300,150);         }      };       } 

try following code:

public static rect locateview(view v) {     int[] loc_int = new int[2];     if (v == null) return null;     try     {         v.getlocationonscreen(loc_int);     } catch (nullpointerexception e)     {         //happens when view doesn't exist on screen anymore.         return null;     }     rect location = new rect();     location.left = loc_int[0];     location.top = loc_int[1];     location.right = location.left + v.getwidth();     location.bottom = location.top + v.getheight();     return location; } 

and use

popup.showatlocation(parent, gravity.top|gravity.left, location.left, location.bottom); 

hope helps...


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -