android典型代码系列(二十五)------popupwindow的使用
16lz
2021-12-20
popupwindow的使用 :
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {/************************** 屏幕适配 ************************************/ int popupWindowWidth = Integer.valueOf(getResources().getString(R.string.popwindowwidth).toString().trim()); int popupWindowHeight = Integer.valueOf(getResources().getString(R.string.popwindowheight).toString().trim()); int dx = Integer.valueOf(getResources().getString(R.string.popwindowdx).toString().trim()); /**********************************************************************/ int[] location = new int[2]; view.getLocationInWindow(location); int x = location[0] + dx; int y = location[1]; AppInfo info = (AppInfo) lv_AppManagerAcitivty.getItemAtPosition(position); View popupWindow = View.inflate(this, R.layout.popwindow, null); ll_start = (LinearLayout) popupWindow.findViewById(R.id.ll_start); ll_uninstall = (LinearLayout) popupWindow.findViewById(R.id.ll_uninstall); ll_share = (LinearLayout) popupWindow.findViewById(R.id.ll_share); ll_start.setTag(position); ll_uninstall.setTag(position); ll_share.setTag(position); ll_start.setOnClickListener(this); ll_uninstall.setOnClickListener(this); ll_share.setOnClickListener(this); localPopupWindow = new PopupWindow(popupWindow, popupWindowWidth,popupWindowHeight); Drawable background = getResources().getDrawable(R.drawable.local_popup_bg);//注意:popwindow一定要设置背景 localPopupWindow.setBackgroundDrawable(background); localPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, x, y);}
更多相关文章
- Android(安卓)Studio学习:简单控件:滚动显示文本
- android maxLines ellipsize 配合使用失效,解决办法
- android 对话框
- android获取屏幕分辨率
- Android填坑记录
- Android快速显示4G
- Android(安卓)OnTouchListener 触摸事件 & GestureDetector 手势
- RecyclerView嵌套ScrollView
- Android6.0修改设备设置中kernel信息