7
目前,我試圖在菜單中點擊按鈕實現彈出菜單如圖以下畫面:創建自定義彈出的對話框菜單
我試圖popupwindow方法,但也無法達到精確的情況。 這是我正在努力:
private View.OnClickListener showPopupWindow() {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupWindow popUp = popupWindowsort();
popUp.showAsDropDown(v, 1, 1); // show popup like dropdown list
}
};
}
private PopupWindow popupWindowsort() {
// initialize a pop up window type
popupWindow = new PopupWindow(context);
ArrayList<String> sortList = new ArrayList<String>();
sortList.add("VIEW FULL");
sortList.add("REPORT");
sortList.add("ADD TO LIST");
sortList.add("ADD TO CART");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.drop_down_line,
sortList);
// the drop down list is a list view
ListView listViewSort = new ListView(context);
// set our adapter and pass our pop up window contents
listViewSort.setAdapter(adapter);
// set on item selected
listViewSort.setOnItemClickListener(onItemClickListener());
// some other visual settings for popup window
popupWindow.setFocusable(true);
popupWindow.setWidth(300);
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
// set the listview as popup content
popupWindow.setContentView(listViewSort);
return popupWindow;
}
private AdapterView.OnItemClickListener onItemClickListener() {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
if (position == 0) {
// adapter.notifyDataSetChanged();
} else if (position == 1) {
report_lay.setVisibility(View.VISIBLE);
// adapter.notifyDataSetChanged();
} else {
// adapter.notifyDataSetChanged();
Log.i(TAG, "position2 " + position);
}
dismissPopup();
}
};
}
private void dismissPopup() {
if (popupWindow != null) {
popupWindow.dismiss();
}
}
,這也是在棉花糖引起問題。
/我如何創建這樣的彈出菜單?任何幫助將不勝感激
你可以添加圖像詳細說明 –
我應該在哪裏添加屏幕截圖 –