private void showPopWindows(View v) {
/** pop view */
View mPopView = LayoutInflater.from(this).inflate(R.layout.popup, null);
final PopupWindow mPopWindow = new PopupWindow(mPopView, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, true);
/** set */
mPopWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
/** 这个很重要 ,获取弹窗的长宽度 */
mPopView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
int popupWidth = mPopView.getMeasuredWidth();
int popupHeight = mPopView.getMeasuredHeight();
/** 获取父控件的位置 */
int[] location = new int[2];
v.getLocationOnScreen(location);
/** 显示位置 */
mPopWindow.showAtLocation(v, Gravity.NO_GRAVITY, (location[0] + v.getWidth() / 2) - popupWidth / 2, location[1]
- popupHeight);
mPopWindow.update();
final String copyTxt = (String) v.getTag();
mPopView.findViewById(R.id.tv_copy_txt).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
copyToClip(copyTxt);
if (mPopWindow != null) {
mPopWindow.dismiss();
}
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/pop_bg" >
<TextView
android:id="@+id/tv_copy_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="复制邀请码"
android:textColor="@android:color/white"
android:textSize="12sp" />
</LinearLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有