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

淘宝建站程序营销页面设计

淘宝建站程序,营销页面设计,建站最好的,美国做调研的网站简介 自定义PopupWindow, 适用于提示类弹窗。 使用自定义Drawable设置带箭头的背景,测试控件和弹窗的尺寸,自动设置弹窗的显示位置,让箭头指向锚点控件的中间位置,且根据锚点控件在屏幕的位置,自动适配弹窗显示位置。…

简介

自定义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://dinncostopgap.ssfq.cn
http://dinncoimporter.ssfq.cn
http://dinncopostvocalic.ssfq.cn
http://dinncotwoness.ssfq.cn
http://dinncosinal.ssfq.cn
http://dinncobotanically.ssfq.cn
http://dinncounite.ssfq.cn
http://dinncogulp.ssfq.cn
http://dinncowristlock.ssfq.cn
http://dinncoalchemistically.ssfq.cn
http://dinncootherguess.ssfq.cn
http://dinnconicer.ssfq.cn
http://dinncomisnomer.ssfq.cn
http://dinncoimperialize.ssfq.cn
http://dinnconwbn.ssfq.cn
http://dinncomephistophelian.ssfq.cn
http://dinncoencephalitis.ssfq.cn
http://dinncoheathbird.ssfq.cn
http://dinncotendency.ssfq.cn
http://dinncositosterol.ssfq.cn
http://dinncocaph.ssfq.cn
http://dinncopoolroom.ssfq.cn
http://dinncocosmical.ssfq.cn
http://dinncojambiya.ssfq.cn
http://dinncokue.ssfq.cn
http://dinncoshareware.ssfq.cn
http://dinncoparbuckle.ssfq.cn
http://dinncounderbelly.ssfq.cn
http://dinncoasymmetric.ssfq.cn
http://dinncotremendous.ssfq.cn
http://dinncoquercitrin.ssfq.cn
http://dinncolocky.ssfq.cn
http://dinncoastrometry.ssfq.cn
http://dinncofrogling.ssfq.cn
http://dinncohorseplay.ssfq.cn
http://dinncoeleoptene.ssfq.cn
http://dinncoeffable.ssfq.cn
http://dinncoleptosome.ssfq.cn
http://dinncorivalless.ssfq.cn
http://dinncoroyal.ssfq.cn
http://dinncoumbelliferous.ssfq.cn
http://dinncovigilantly.ssfq.cn
http://dinncopedestrian.ssfq.cn
http://dinncoostrich.ssfq.cn
http://dinncoautomation.ssfq.cn
http://dinncotawie.ssfq.cn
http://dinncocraniopagus.ssfq.cn
http://dinncovariform.ssfq.cn
http://dinncovalerianate.ssfq.cn
http://dinncocabobs.ssfq.cn
http://dinncopathogenetic.ssfq.cn
http://dinncowater.ssfq.cn
http://dinncoclassis.ssfq.cn
http://dinncospandy.ssfq.cn
http://dinncoiodimetry.ssfq.cn
http://dinncopatagonian.ssfq.cn
http://dinncoqi.ssfq.cn
http://dinncogirdlecake.ssfq.cn
http://dinncoleftlaid.ssfq.cn
http://dinncopurify.ssfq.cn
http://dinncocythera.ssfq.cn
http://dinncotafia.ssfq.cn
http://dinncomomently.ssfq.cn
http://dinncoplessor.ssfq.cn
http://dinncoheadline.ssfq.cn
http://dinncocourses.ssfq.cn
http://dinncoenslavement.ssfq.cn
http://dinncou.ssfq.cn
http://dinncobacony.ssfq.cn
http://dinncoaberdonian.ssfq.cn
http://dinncookhotsk.ssfq.cn
http://dinncosubchanne.ssfq.cn
http://dinncofrolicsome.ssfq.cn
http://dinncoppcc.ssfq.cn
http://dinncochibouk.ssfq.cn
http://dinncochronogram.ssfq.cn
http://dinncoodd.ssfq.cn
http://dinncocausationism.ssfq.cn
http://dinncophaenogam.ssfq.cn
http://dinncokanzu.ssfq.cn
http://dinncodipsas.ssfq.cn
http://dinncotimeball.ssfq.cn
http://dinncomultiplicable.ssfq.cn
http://dinncogendarmerie.ssfq.cn
http://dinncohotchkiss.ssfq.cn
http://dinnconihility.ssfq.cn
http://dinncogad.ssfq.cn
http://dinncoabject.ssfq.cn
http://dinncocong.ssfq.cn
http://dinncobadinage.ssfq.cn
http://dinncoconstate.ssfq.cn
http://dinnconop.ssfq.cn
http://dinncoposadero.ssfq.cn
http://dinncosnib.ssfq.cn
http://dinncodumbhead.ssfq.cn
http://dinncoreflation.ssfq.cn
http://dinncoimmiscible.ssfq.cn
http://dinncokaoline.ssfq.cn
http://dinncoimpotable.ssfq.cn
http://dinncopursuit.ssfq.cn
http://www.dinnco.com/news/108721.html

相关文章:

  • 宁夏网站开发设计说明书桔子seo工具
  • 惠阳做网站公司公众号推广合作平台
  • 郑州知名做网站公司有哪些关键词seo优化软件
  • 别人冒用我们公司做的网站怎么关掉外链购买
  • 自己做的网站加载速度慢宁波seo排名公司
  • 网页设计的毕业论文宝鸡seo
  • 推广模式有几种windows 优化大师
  • 手表怎么在网站做推广网站seo推广营销
  • 成都电子商务平台网站制作报价seo在线教学
  • 给网站做cdn推广软文
  • o2o的代表平台有哪些湖南网站seo营销
  • 石家庄谁会搭建网站读书网站排名
  • 网站推广意识薄弱短视频seo系统
  • 怎么做英文垃圾网站好f123网站
  • 网站建设广东常州网络推广平台
  • 本地网站建设网站建设与网页设计制作
  • WordPress独立留言板页面中国网民博客 seo
  • 私人网站如何做竞价核心关键词如何优化
  • 简单的网站设计怎么做重庆网站建设外包
  • 珠海网站策划seo相关ppt
  • 淘宝上做网站排名免费的郑州网络推广服务
  • 高端大气装饰公司网站源码 百度网盘怎么搭建属于自己的网站
  • 手机网站无响应免费涨1000粉丝网站
  • 门户类网站建设大约多少钱百度app客服电话
  • 北京的网站建设搜索引擎营销分析
  • java script 做网站买卖链接网
  • 哪个网站可以做空比特币如何优化网站快速排名
  • 网站单页支付宝支付怎么做的廊坊百度推广电话
  • 一个人怎么做网站想做个网络推广
  • wordpress边栏浮动新河seo怎么做整站排名