當popupWindow內巢狀recyclerView佈局過長的時候會被頂上去的問題
阿新 • • 發佈:2019-02-06
最近在寫一個自定義的popupWindow的時候,裡面巢狀recyclerView佈局,recyclerView內是個自定義的佈局,但是當資料過多的時候popupwindow設定在某個控制元件下方的時候就不準確了,會被頂上去,這樣就達不到效果了,解決方法如下首先你需要自定義一個popupWindow,重寫showAsDropDown方法。直接上程式碼
@Override public void showAsDropDown(View anchor) { if(Build.VERSION.SDK_INT == 24) { Rect rect = new Rect(); anchor.getGlobalVisibleRect(rect); int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom; setHeight(h); } super.showAsDropDown(anchor); } @Override public void showAsDropDown(View anchor, int xoff, int yoff) { if(Build.VERSION.SDK_INT == 24) { Rect rect = new Rect(); anchor.getGlobalVisibleRect(rect); int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom; setHeight(h); } super.showAsDropDown(anchor, xoff, yoff); }