点击一个图片更换成另一个图片,并且弹出popupwindow

阅读: 评论:0

点击一个图片更换成另一个图片,并且弹出popupwindow

点击一个图片更换成另一个图片,并且弹出popupwindow

第一步:在那个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小时内删除。

标签:图片   弹出   popupwindow
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23