第一步:在那个id中
case R.id.supmart_img:if (v == supmart_img) {if (isChanged) {supmart_img.setImageDrawable(getResources().getDrawable(R.mipmap.yuan));} else {showPopUp(v);supmart_img.setImageDrawable(getResources().getDrawable(R.mipmap.seyuan));}isChanged = !isChanged;}break;
boolean isChanged = false;
private void showPopUp(View parent) {view2 = LayoutInflater.from(SupmartActivity.this).inflate(R.layout.popu2, null);popupWindow = new PopupWindow(view2, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);// 获取popwindow焦点 popupWindow.setFocusable(true);// 点击PopupWindow区域外部消失 popupWindow.setOutsideTouchable(true);popupWindow.setBackgroundDrawable(new BitmapDrawable());// 设置popwindow出现和消失动画 // popupWindow.setAnimationStyle(R.style.PopMenuAnimation); // 获取点击按钮的坐标 int[] location = new int[2];supmart_img.getLocationOnScreen(location);// 设置popwindow显示位置 popupWindow.showAtLocation(supmart_img, Gravity.NO_GRAVITY, location[0], location[1] - popupWindow.getHeight());popupWindow.showAsDropDown(supmart_img);}
第二步:popup2布局中
<LinearLayout android:background="@color/colorPrimary" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="50dp"><Button android:background="#0000" android:id="@+id/xiaoxingquan" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15px" android:button="@null" android:layout_weight="1" android:text="水果" android:textColor="#cd333333" /><Button android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15px" android:button="@null" android:background="#0000" android:text="香烟" android:textColor="#cd333333" /><Button android:background="#0000" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15px" android:button="@null" android:layout_weight="1" android:text="酒水" android:textColor="#cd333333" /><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15px" android:button="@null" android:layout_weight="1" android:text="蔬菜" android:background="#0000" android:textColor="#cd333333" /><Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15px" android:button="@null" android:layout_weight="1" android:text="冷饮" android:background="#0000" android:textColor="#cd333333" /></LinearLayout>
转载于:
本文发布于:2024-02-01 18:40:57,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170678405738670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |