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

技术支持公司做的网站怎么查用vue做pc端网站好吗

技术支持公司做的网站怎么查,用vue做pc端网站好吗,建立企业网站地址,银川建立网站问题 在使用Popwindow进行自定义的过程中&#xff0c;需要设置popwindow的宽高。但是宽高很多时候容易出问题。比如下面的例子。 布局文件如下 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.andr…

问题

在使用Popwindow进行自定义的过程中,需要设置popwindow的宽高。但是宽高很多时候容易出问题。比如下面的例子。

布局文件如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#77000000"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:background="#fff"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="44dp"android:layout_margin="12dp"android:background="@drawable/cz_add_rzh_bg"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:drawableStart="@drawable/cz_icon_add_rzh"android:drawablePadding="4dp"android:text="申请注册入驻号"android:textColor="#ff333333"android:textSize="14sp" /></RelativeLayout></LinearLayout><Viewandroid:id="@+id/close_layout"android:layout_width="match_parent"android:layout_height="100dp"/>
</LinearLayout>

使用了传统方法设置宽高
在这里插入图片描述
实际显示效果很差,没有内容只有一个黑色透明背景。
在这里插入图片描述

解决方案

为了解决这个问题,我写了个工具类。原理就是内部创建一个铺面全屏的FrameLayout。在填充布局的时候作为父布局,来自动计算宽高。在通过其内部的LayoutParam来获取宽高,如果宽高是-1的话,(MATCH_PARENT的值)就替换成屏幕的宽高。在编程实践中Popwindow一般会显示在某个控件的下面,这个时候布局中的高度match_parent对应的就不是手机屏幕的高度,而是需要减去上方空间占用的高度。这个时候就可以传入上方控件,可以自动计算被使用的高度。

优化

加入了顶部view的处理

package com.trs.nmip.common.util.web;import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;import androidx.annotation.LayoutRes;/*** @author: zhuguohui* @date: 2025/3/21* @description: 用于获取View大小的工具类*/
public class ViewSizeUtil {private static FrameLayout fullScreenView;private static FrameLayout getFullScreenView(Context ctx) {if (fullScreenView == null) {fullScreenView = new FrameLayout(ctx);fullScreenView.measure(getWidthMeasureSpec(ctx), getHeightMeasureSpec(ctx));fullScreenView.layout(0, 0, getScreenWidth(ctx), getScreenHeight(ctx));}return fullScreenView;}public static class Size {public  int width;public  int height;public Size(int width, int height) {this.width = width;this.height = height;}}/*** 填充布局,获取宽高,用于在没有父view的情况下,计算宽高** @param ctx      上下文* @param layoutId 布局id* @param topView  在其上面的控件,比如popWindow,如果要显示在某个控件下面,并且当前控件的高度需要铺面全屏的话。*                 那么就会减去topView所占用的高度。* @return 一个pair对象,第一个元素是view,第二个是宽高*/public static Pair<View, Size> inflateViewAndGetSize(Context ctx, @LayoutRes int layoutId, View topView, int yOffset) {View view = LayoutInflater.from(ctx).inflate(layoutId, getFullScreenView(ctx), false);ViewGroup.LayoutParams layoutParams = view.getLayoutParams();int width = layoutParams.width;int height = layoutParams.height;if (width == -1) {width = getScreenWidth(ctx);}if (height == -1) {height = getScreenHeight(ctx);//如果是铺满全屏,还要显示在某个控件下面,需要减去这个控件使用的距离if (topView != null) {int[] location = new int[2];topView.getLocationOnScreen(location);int useHeight = location[1] + topView.getHeight();height -= useHeight;}}height += yOffset;return new Pair<>(view, new Size(width, height));}private static int getScreenWidth(Context context) {WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);DisplayMetrics dm = new DisplayMetrics();wm.getDefaultDisplay().getMetrics(dm);return dm.widthPixels;}private static int getScreenHeight(Context context) {DisplayMetrics displayMetrics = new DisplayMetrics();((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRealMetrics(displayMetrics);int screenHeight = displayMetrics.heightPixels;return screenHeight;}private static int getWidthMeasureSpec(Context ctx) {return View.MeasureSpec.makeMeasureSpec(getScreenWidth(ctx), View.MeasureSpec.AT_MOST);}private static int getHeightMeasureSpec(Context ctx) {return View.MeasureSpec.makeMeasureSpec(getScreenHeight(ctx), View.MeasureSpec.AT_MOST);}}

使用方法如下。

public class ChangeRzhPopWindow extends PopupWindow {public ChangeRzhPopWindow(Context context,View topView) {super(context);Pair<View, ViewSizeUtil.Size> pair = ViewSizeUtil.inflateViewAndGetSize(context, R.layout.change_rzh_pop_window,topView);setContentView(pair.first);setWidth(pair.second.width);setHeight(pair.second.height);setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));setFocusable(true);setOutsideTouchable(true);//因为背景是我们创建的。所以需要我们实现点击背景关闭的功能pair.first.findViewById(R.id.close_layout).setOnClickListener(v-> dismiss());}
}

效果如下

红色的地方就是顶部view

在这里插入图片描述

遇到的问题

在开发中遇到一个通过代码获取的屏幕高度和手机时间高度不一致的情况,通过AI查询得到这样的结果。测试没问题。特此记录一下。

在这里插入图片描述

提取基类

把上面的功能提取一个基类。这样可以方便处理这些问题。这个基类还实现了LifecycleOwner 。更方便使用。

package com.trs.app.gzcz.content_manage.ui.rzh_title_bar.change_rzh_pop_window;import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.Pair;
import android.view.View;
import android.widget.PopupWindow;import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;import com.trs.news.R;
import com.trs.nmip.common.util.web.ViewSizeUtil;/**** @author: zhuguohui* @date: 2025/3/21* @description: 自动处理宽高的PopupWindow* 加入了LifeCycleOwner的功能*/
public class EasySizePopupWindow extends PopupWindow implements LifecycleOwner {LifecycleRegistry registry=new LifecycleRegistry(this);{registry.setCurrentState(Lifecycle.State.INITIALIZED);}protected void setContentView(Context context, @LayoutRes  int layoutId, View topView,int yOffset){Pair<View, ViewSizeUtil.Size> pair = ViewSizeUtil.inflateViewAndGetSize(context, layoutId,topView,yOffset);setContentView(pair.first);setWidth(pair.second.width);setHeight(pair.second.height);setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));setFocusable(true);setOutsideTouchable(true);//因为背景是我们创建的。所以需要我们实现点击背景关闭的功能pair.first.findViewById(R.id.close_layout).setOnClickListener(v-> dismiss());}@Overridepublic void showAsDropDown(View anchor) {super.showAsDropDown(anchor);}@Overridepublic void showAsDropDown(View anchor, int xoff, int yoff) {super.showAsDropDown(anchor, xoff, yoff);}@Overridepublic void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {super.showAsDropDown(anchor, xoff, yoff, gravity);updateLifecycleState();}@Overridepublic void showAtLocation(View parent, int gravity, int x, int y) {super.showAtLocation(parent, gravity, x, y);updateLifecycleState();}@Overridepublic void dismiss() {super.dismiss();updateLifecycleStateToDismiss();}private void updateLifecycleStateToDismiss(){registry.setCurrentState( Lifecycle.State.CREATED);registry.setCurrentState( Lifecycle.State.STARTED);registry.setCurrentState( Lifecycle.State.DESTROYED);}private void updateLifecycleState(){registry.setCurrentState( Lifecycle.State.CREATED);registry.setCurrentState( Lifecycle.State.STARTED);registry.setCurrentState( Lifecycle.State.RESUMED);}@NonNull@Overridepublic Lifecycle getLifecycle() {return registry;}
}

使用

public class ChangeRzhPopWindow extends EasySizePopupWindow {public ChangeRzhPopWindow(Context context, View topView) {super();setContentView(context, R.layout.change_rzh_pop_window, topView);//因为背景是我们创建的。所以需要我们实现点击背景关闭的功能getContentView().findViewById(R.id.close_layout).setOnClickListener(v-> dismiss());}}

关于全屏高度问题

如果当前页面的布局是沉浸式的。那么使用PopupWindowshowAsDropDown会出现位置不对的情况。需要加上偏移量。
就可以完美显示了。
在这里插入图片描述

http://www.dtcms.com/a/473273.html

相关文章:

  • 网站备案 更名wordpress 404插件
  • 创世网站建设 优帮云百度帐号申请注册
  • 标杆网站建设自己建设网站不会咋办呀
  • 长椿街网站建设悦然wordpress建站服务
  • 番禺响应式网站建设深圳制作网站培训学校
  • 网站建设加数据库彩票计划网站怎么做
  • 哪些网站做代理网站地图 制作
  • 厦门专业网站建设建站黑龙江省住房和城乡建设部网站
  • 怎么查网站流量wordpress 桌面
  • 小说在线阅读网站怎么做网络营销推广方案案例分析
  • 邵阳做网站建设优秀营销网站设计
  • 本溪 网站建设 做网站建地方门户网站
  • 制作一个网站需要多少小时如何建设本地网站
  • 做网站讯息制作h5的基本流程
  • 河南城乡建设部网站一定要用c 做网站吗
  • wordpress 插件 留言seo推广分析
  • 做家装壁纸的网站宇泽佛山网站建设
  • 创建一个网站的项目体现项目完成速度因素的网架厂家
  • 泰安网站开发公司cms视频系统大全
  • 太原网站优化怎么做网络seo优化公司
  • 网站全屏宽度是多少合适seo基础课程
  • 用手机建网站世界优秀摄影作品网站
  • php模板建站百度做网站续费费用
  • 专业做网站排名的人北京搜索引擎推广服务
  • wordpress适合下载站的主题国外购物网站app
  • php网站开发实例教程简介寮步做网站公司
  • 营销网站建设推广安徽省工程建设信息网职称查询
  • 摄影网站网址大全app电商网站
  • 信阳网站建设找汉狮建筑网站大全免费
  • 北京建设工程网站小程序软件开发制作