2017-02-01 8 views
2

を働いていない:Androidのヌガー7.1.1 showAtLocation(...)重力がこれはこの質問に関連している

if (android.os.Build.VERSION.SDK_INT >=24) { 
    int[] a = new int[2]; 
    anchorView.getLocationInWindow(a); 
    popUp.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0 , a[1]+anchorView.getHeight()); 
} else{ 
    popUp.showAsDropDown(anchorView); 
} 

それは動作しません:私はこの修正プログラムを適用した場合に、しかし Android Nougat PopupWindow showAsDropDown(...) Gravity not working

Android Nougat 7.1.1で特にGoogle PixelとNexus 6pデバイスでは

これについて誰かが修正を得ましたか?シェアしてください。 https://code.google.com/p/android/issues/detail?id=231487

+0

この問題の回避策を見つけましたか?そうでない場合は、ここでバグレポートを書いています:https://code.google.com/p/android/issues/detail?id=233237 –

答えて

3

私はWindowManager.LayoutParams.MATCH_PARENTからWindowManager.LayoutParams.WRAP_CONTENTにPopupWindowの高さを変更すると、それは、Android 7.1上で動作しますが、私はその理由を知らないが、多分あなたはそれを試すことができます。

はまた、あなたがあなたのコードを変更する必要があります。

if (android.os.Build.VERSION.SDK_INT == 24) { 
    int[] a = new int[2]; 
    anchorView.getLocationInWindow(a); 
    popUp.showAtLocation(((Activity)mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0 , a[1]+anchorView.getHeight()); 
} else{ 
    popUp.showAsDropDown(anchorView); 
} 
+0

私たちにとってはうまくいかないのです。私の端末はNexus 5x Android 7.1.1です – Jimson

0

私は私のネクサス5 7.1.1 alreadはバグがあり、それを修正しました。 サンプルコード:

View rootView = anchor.getRootView(); 
    Rect rect = new Rect(); 
    rootView.getWindowVisibleDisplayFrame(rect); 

    int[] xy = new int[2]; 
    anchor.getLocationInWindow(xy); 
    int anchorY = xy[1] + anchor.getHeight(); 

    int height = rect.bottom - anchorY; 

    PopupWindow poupWindow = new PopupWindow(frameLayout, ViewGroup.LayoutParams.MATCH_PARENT, height); 
    poupWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, 0, anchorY);  
0
public void showFilterWindow(Context context, PopupWindow popupWindow,View showView, int xoff, int yoff) { 
    if (Build.VERSION.SDK_INT < 24) { 
     //7.0 The following system is used normally 
     popupWindow.showAsDropDown(showView, xoff, yoff); 
    } else { 
     int[] location = new int[2]; 
     showView.getLocationOnScreen(location); 
     int offsetY = location[1] + showView.getHeight() + yoff; 
     if (Build.VERSION.SDK_INT == 25) { 
      //【note!】Gets the screen height without the virtual key 
      WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
      int screenHeight = wm.getDefaultDisplay().getHeight(); 
      /* 
      * PopupWindow height for match_parent, 
      * will occupy the entire screen, it needs to do special treatment in Android 7.1 
      */ 
      popupWindow.setHeight(screenHeight - offsetY); 
     } 
     //Use showAtLocation to display pop-up windows 
     popupWindow.showAtLocation(showView, Gravity.NO_GRAVITY, 0, offsetY); 
    } 
} 

リファレンスhttps://stackoverflow.com/a/43873648/4776543いくつかのバグを修正。

関連する問題