我正在嘗試使用 PopupWindow 來膨脹布局,但我在互聯網上沒有找到任何示例。能不能教教我怎么用。
這是我當前的代碼,但沒有顯示 popupWindow
private void ShowMenu(ImageButton anchor, Dictionary<string, object> data)
{
LayoutInflater inflater = (LayoutInflater)_context.GetSystemService(Context.LayoutInflaterService);
View popupView = inflater.Inflate(Resource.Layout.menu_outlet_buttons, null);
int width = LinearLayout.LayoutParams.WrapContent;
int height = LinearLayout.LayoutParams.WrapContent;
bool focusable = true;
PopupWindow popupWindow = new PopupWindow(popupView.Context);
popupWindow.ShowAtLocation(_view, GravityFlags.Center, 0, 0);
}
順便說一句,這是一個配接器
public MyAdapter(List<Dictionary<string, object>> data, Context context)
{
_data = data;
_context = context;
}
這是我的參考,但我無法在 Xamarin Android 中重現相同的內容。
如何在Android中創建一個彈出視窗(PopupWindow)
uj5u.com熱心網友回復:
您創建 PopupWindow 實體的方法是錯誤的。我在我的專案中嘗試了以下代碼,效果很好:
View view = LayoutInflater.Inflate(Resource.Layout.popup, null);
PopupWindow popupWindow = new PopupWindow(view,LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent,true);
popupWindow.ShowAtLocation(view, GravityFlags.Center, 0, 0);
更新:
我檢查了 popupWindow.ShowAtLocation 方法,第一個引數是父視圖。
您可以通過以下代碼獲取 x,y:
int[] location = new int[2];
imagebutton.GetLocationOnScreen(location);
int x = location[0];
int y = location[1];
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/493334.html