当前位置: 首页 > news >正文

衡水网站网站建设郑州网站建设搜索优化

衡水网站网站建设,郑州网站建设搜索优化,心理咨询中心网站模板,wordpress now简介 自定义PopupWindow, 适用于提示类弹窗。 使用自定义Drawable设置带箭头的背景#xff0c;测试控件和弹窗的尺寸#xff0c;自动设置弹窗的显示位置#xff0c;让箭头指向锚点控件的中间位置#xff0c;且根据锚点控件在屏幕的位置#xff0c;自动适配弹窗显示位置。…简介 自定义PopupWindow, 适用于提示类弹窗。 使用自定义Drawable设置带箭头的背景测试控件和弹窗的尺寸自动设置弹窗的显示位置让箭头指向锚点控件的中间位置且根据锚点控件在屏幕的位置自动适配弹窗显示位置。  适用于描述、解释弹窗。 一、效果 带箭头弹窗显示在控件的左侧箭头相对控件居中对齐 且与控件左边框挨着 示例代码如下 二、使用 GuZhiExplainPupopWindow window new GuZhiExplainPupopWindow(this);//设置弹窗显示文案window.setTips(1234567890-34567890-【qweqwertyuiop[sdfghjkl;zxcvbnm,.我们一起走向富强);//获取窗口的背景drawable对象ArrowsDrawable ad window.getArrowsDrawable();//设置drawable箭头的大小ad.setArrowsHeight(ConvertUtils.dp2px(8));//设置drawable中箭头与边框距离ad.setArrowsPadding(ConvertUtils.dp2px(10));//设置drawable的padding, 实际是设置显示文案的TextView的padding//ad.setPadding(ConvertUtils.dp2px(10));window.setPadding(ConvertUtils.dp2px(10));//设置drawable背景色ad.setColor(Color.DKGRAY);findViewById(R.id.tv33).setOnClickListener(view - {if (!window.isShowing()) {//设置窗口显示位置AUTO_HORIZONTAL 是水平位置在控件的左侧或右侧根据控件中心在屏幕中的位置决定window.setShowPosition(GuZhiExplainPupopWindow.AUTO_HORIZONTAL);//显示弹窗偏移量是0默认是箭头在控件居中位置window.show(view, 0, 0);}}); 三、自定义布局 重写initView方法并设置TipsTv 同时需要注意的是在设置弹窗布局时根布局的宽高属性是wrap_content设置其它是不生效的如果需要指定textView的宽或高或弹窗尺寸根布局使用某ViewGroup控件再设置其子控件的尺寸。 GuZhiExplainPupopWindow window new GuZhiExplainPupopWindow(this, R.layout.pupopwindow_view_guzhi_explain) {Overridepublic void initView(View contentView) {//自定义布局初始化控件super.initView(contentView);TextView customTv contentView.findViewById(R.id.explain_tv);setTipsTv(customTv);}}; 四、源码 package com.ttkx.deviceinfo.bkchart.popupwindow;import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.PopupWindow; import android.widget.TextView;import com.blankj.utilcode.util.ConvertUtils; import com.blankj.utilcode.util.Utils; import com.ttkx.deviceinfo.R; import com.ttkx.deviceinfo.bkchart.ArrowsDrawable; import com.ttkx.deviceinfo.bkchart.GuZhiActivity;import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy;import androidx.annotation.IntDef; import androidx.core.widget.PopupWindowCompat;/*** 估值说明弹窗* Created by liuyu*/ public class SimpleTipsPupopWindow extends PopupWindow {private ArrowsDrawable mBgDrawable;private TextView mTipsTv;private int mShowPosition TOP;public static final int AUTO_VERTICAL Gravity.CENTER_VERTICAL;public static final int AUTO_HORIZONTAL Gravity.CENTER_HORIZONTAL;public static final int LEFT Gravity.LEFT;public static final int TOP Gravity.TOP;public static final int RIGHT Gravity.RIGHT;public static final int BOTTOM Gravity.BOTTOM;public SimpleTipsPupopWindow(GuZhiActivity context) {this(context, View.inflate(context, R.layout.pupopwindow_view_guzhi_explain, null));}public SimpleTipsPupopWindow(GuZhiActivity context, int layoutId) {this(context, View.inflate(context, layoutId, null));}public SimpleTipsPupopWindow(GuZhiActivity context, View contentView) {super(context);setContentView(contentView);setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));setOutsideTouchable(true);init(contentView);}private void init(View contentView) {mBgDrawable new ArrowsDrawable(ArrowsDrawable.TOP, ConvertUtils.dp2px(5));mBgDrawable.setCornerRadius(ConvertUtils.dp2px(4));mBgDrawable.setArrowsPadding(ConvertUtils.dp2px(10));mBgDrawable.setArrowsHeight(ConvertUtils.dp2px(5));boolean redMode true;mBgDrawable.setColor(Color.parseColor(redMode ? #e6292F3C : #f22b3346)); // mBgDrawable.setPadding(ConvertUtils.dp2px(10));mTipsTv contentView.findViewById(R.id.explain_tv);initView(contentView);}/*** 用于自定义布局 初始化* param contentView*/public void initView(View contentView) {}/*** 设置tips TextView* param tv*/public void setTipsTv(TextView tv) {mTipsTv tv;}private int makeDropDownMeasureSpec(int measureSpec) {int mode;if (measureSpec ViewGroup.LayoutParams.WRAP_CONTENT) {mode View.MeasureSpec.UNSPECIFIED;} else {mode View.MeasureSpec.EXACTLY;}return View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(measureSpec), mode);}public void setTips(String tips) {if (mTipsTv ! null) {mTipsTv.setText(tips);}}public void show(View anchor, int os, int oy) {if (mBgDrawable null) {return;}int showPosition mShowPosition;int offsetX 0;int offsetY 0;int locationX getLocationOnScreen(anchor)[0];int locationY getLocationOnScreen(anchor)[1];if (showPosition LEFT || showPosition RIGHT || showPosition AUTO_HORIZONTAL) {mBgDrawable.setArrowsPosition(ArrowsDrawable.LEFT, mTipsTv);getContentView().measure(makeDropDownMeasureSpec(getWidth()), makeDropDownMeasureSpec(getHeight()));int windowWidth this.getContentView().getMeasuredWidth();os anchor.getWidth();offsetY (int) -(anchor.getHeight() / 2 mBgDrawable.getArrowsCenterDistance());if (showPosition LEFT) {boolean showLeft locationX windowWidth;offsetX disHor(showLeft, windowWidth, anchor, os);} else if (showPosition RIGHT) {boolean showLeft !(getAppScreenWidth() - (locationX anchor.getWidth()) windowWidth);offsetX disHor(showLeft, windowWidth, anchor, os);} else if (showPosition AUTO_HORIZONTAL) {int screenWidth getAppScreenWidth();boolean showLeft locationX anchor.getWidth() / 2 screenWidth / 2;offsetX disHor(showLeft, windowWidth, anchor, os);}} else {mBgDrawable.setArrowsPosition(ArrowsDrawable.TOP, mTipsTv);//先设置箭头drawable方向为垂直方向的因箭头尺寸会影响到计算窗口的高度getContentView().measure(makeDropDownMeasureSpec(getWidth()), makeDropDownMeasureSpec(getHeight()));int windowHeight this.getContentView().getMeasuredHeight();os anchor.getWidth() / 2;offsetX (int) (os - mBgDrawable.getArrowsCenterDistance());if (showPosition TOP) {int distanceTop locationY - getStatusBarHeight();//锚点控件距离顶部距离//计算锚点控件在屏幕中的位置offsetY disVer(distanceTop windowHeight, windowHeight, anchor, oy);} else if (showPosition BOTTOM) {int distanceBottom getLocationOnScreen(anchor)[1] - anchor.getHeight() - getNavBarHeight();//锚点控件距离底部距离offsetY disVer(distanceBottom windowHeight, windowHeight, anchor, oy);} else if (showPosition AUTO_VERTICAL) {int appScreenHeight getAppScreenHeight();int anchorCenterY locationY anchor.getHeight() / 2;offsetY disVer(appScreenHeight / 2 anchorCenterY, windowHeight, anchor, oy);}}//设置textView的padding防止设置drawable背景不生效Rect padding mBgDrawable.getPadding();mTipsTv.setPadding(padding.left, padding.top, padding.right, padding.bottom);PopupWindowCompat.showAsDropDown(this, anchor, offsetX, offsetY, Gravity.START);}private int disHor(boolean showLeft, int windowWidth, View anchor, int ox) {int offsetX;if (showLeft) {//锚点控件在屏幕中上方反之在屏幕中下方mBgDrawable.setArrowsPosition(ArrowsDrawable.RIGHT);offsetX -windowWidth ox - anchor.getWidth();} else {mBgDrawable.setArrowsPosition(ArrowsDrawable.LEFT);offsetX ox;}return offsetX;}private int disVer(boolean showTop, int windowHeight, View anchor, int oy) {int offsetY 0;if (showTop) {//锚点控件在屏幕中上方反之在屏幕中下方mBgDrawable.setArrowsPosition(ArrowsDrawable.BOTTOM);offsetY -(windowHeight anchor.getHeight() oy);} else {mBgDrawable.setArrowsPosition(ArrowsDrawable.TOP);offsetY oy;}return offsetY;}public ArrowsDrawable getArrowsDrawable() {return mBgDrawable;}public void setPadding(int padding) {mBgDrawable.setPadding(padding);}IntDef({LEFT, RIGHT, TOP, BOTTOM, AUTO_VERTICAL, AUTO_HORIZONTAL})Retention(RetentionPolicy.SOURCE)public interface ShowPosition {}/*** 设置显示位置相对于锚点控件 左边、上方、右边、下面* 注意窗口相对控件的方向与箭头方向是相反的。* LEFT, RIGHT, TOP, BOTTOM** param showPosition*/public void setShowPosition(ShowPosition int showPosition) {mShowPosition showPosition;}private static int[] getLocationOnScreen(View view) {int[] location new int[2];view.getLocationOnScreen(location);return location;}private static int getStatusBarHeight() {// 获得状态栏高度Resources resources Resources.getSystem();int resourceId resources.getIdentifier(status_bar_height, dimen, android);return resources.getDimensionPixelSize(resourceId);}private static int getNavBarHeight() {Resources res Resources.getSystem();int resourceId res.getIdentifier(navigation_bar_height, dimen, android);if (resourceId ! 0) {return res.getDimensionPixelSize(resourceId);} else {return 0;}}private static int getAppScreenHeight() {WindowManager wm (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);if (wm null) return -1;Point point new Point();wm.getDefaultDisplay().getSize(point);return point.y;}private static int getAppScreenWidth() {WindowManager wm (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);if (wm null) return -1;Point point new Point();wm.getDefaultDisplay().getSize(point);return point.x;} }
http://www.hkea.cn/news/14445806/

相关文章:

  • 怎样做百度推广网站手工制作图片作品
  • 做减肥餐的网站手机网站设计趋势
  • 李沧网站建设谁家好wordpress灯箱代码
  • 做站群什么样的算是违法网站黑龙江建设工程网
  • 租车网站模板下载公司门户官网
  • 网站建设系统服务国外优秀个人网页设计欣赏
  • 海外网站推广优化专员python做网站商城开发
  • 新密做网站优化全国特种作业人员证查询
  • 购物网站模板下载淄博专业网站建设哪家专业
  • 海南省城乡建设部网站首页魅影传说网页游戏开服表
  • 学习软件编程软件优化
  • 孝感网站建设磁力链
  • 海北公司网站建设价格低wordpress插件c
  • 同程网站建设分析安阳网站建设开发
  • 400电话申请网站源码程序天津都有哪些制作网站
  • wordpress图片轮播插件重庆seo技术教程
  • wordpress忘记密码ftp廊坊网站的优化
  • 维护公司网站建设个人网站首页布局
  • 四川工程建设项目一般挂什么网站电商软件开发平台
  • 成都网站建设电话咨询百度网络营销app下载
  • 顺德微网站建设电脑字体wordpress
  • 电子商务网站建设人才调研做英语教具的网站
  • 这几年做哪个网站致富女孩做网站工作辛苦吗
  • server 2012 iis 添加网站how to use wordpress
  • 济南网站建设及推广网站建设流量从哪里来
  • 用什么软件做网站模板做家具网站要多少钱
  • 济宁做网站有哪几家手机网站建设ppt
  • 网站做网站反向代理违法价格网
  • 网站开发合同里的坑phpcmsv9手机网站源码
  • 中国设计联盟网服务内容常州seo收费