android dialog的沙雕问题(宽度不充满全屏)

2023-10-31 23:31

本文主要是介绍android dialog的沙雕问题(宽度不充满全屏),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 1.这是显示的效果,右上角的叉号被莫名其妙的遮挡住了 

 2.下面这个是修改后的 使用的是用一个手机

 问题就是这么的莫名其妙,在某些手机上显示的就是正常的,但是在某些手机就是非正常显示,开始我也找不到问题的解决办法,不知道是哪里的问题,后来我冷静分析,会不会是布局的问题

我给dialog设置了背景色,测试了一下,结果还是不行,左边的图片就是充不满

这下面是我的布局代码 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:visibility="visible">
<!--marginEnd 和 marginStart是我后来找到了解决方案,按照蓝湖的边距增加的--><LinearLayoutandroid:layout_marginEnd="@dimen/dp_40"android:layout_marginStart="@dimen/dp_40"android:id="@+id/imageView2"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:layout_marginTop="@dimen/dp_93"android:background="@drawable/dialog_version"android:orientation="vertical"><ImageViewandroid:layout_width="match_parent"android:layout_height="@dimen/dp_156"android:scaleType="fitXY"android:src="@mipmap/update" /><TextViewandroid:id="@+id/tvTitle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginLeft="@dimen/dp_10"android:layout_marginRight="@dimen/dp_10"android:ellipsize="end"android:gravity="center"android:maxLines="2"android:text=""android:textColor="@color/textColor333"android:textSize="@dimen/sp_17" /><cn.qbang.tch.rpc.view.MaxHeightRecyclerViewandroid:id="@+id/recycler_version"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginStart="@dimen/dp_20"android:layout_marginTop="@dimen/dp_6"android:layout_marginEnd="@dimen/dp_20"android:layout_marginBottom="11dp"android:overScrollMode="always"android:scrollbarSize="@dimen/dp_2"android:scrollbarThumbVertical="@color/textColor888"android:scrollbars="vertical"android:visibility="visible"app:maxHeight="@dimen/dp_157" /><RelativeLayoutandroid:id="@+id/rlbottom"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="@dimen/dp_10"android:visibility="visible"><TextViewandroid:id="@+id/tvUpdate"android:layout_width="@dimen/dp_161"android:layout_height="@dimen/dp_40"android:layout_marginStart="@dimen/dp_65"android:layout_marginEnd="@dimen/dp_65"android:layout_marginBottom="@dimen/dp_10"android:background="@mipmap/update_btn_bg"android:gravity="center"android:text=""android:textColor="@color/colorefefef"android:textSize="@dimen/sp_15"android:visibility="gone" /><TextViewandroid:id="@+id/tvReport"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/tvUpdate"android:layout_centerHorizontal="true"android:paddingBottom="@dimen/dp_10"android:text=""android:textColor="@color/colorEF1A2D"android:textSize="@dimen/sp_10"android:visibility="gone" /></RelativeLayout></LinearLayout><ImageViewandroid:id="@+id/tvClose"android:layout_width="@dimen/dp_25"android:layout_height="@dimen/dp_25"android:layout_alignTop="@+id/imageView2"android:layout_alignEnd="@+id/imageView2"android:layout_marginTop="@dimen/dp_m_12"android:layout_marginEnd="@dimen/dp_m_12"android:src="@mipmap/icon_cancle_circle" /></RelativeLayout>
</RelativeLayout>

这是我的预览图,看着也没什么问题

 昨天下午想了一下午解决方案 ,找不到,快下班的时候突发奇想,想到了,既然dialog宽度没有充满全屏,那我把dialog充满全屏左右在设置边距是不是就可以了

说干就干

在dialog的show方法之后调用,设置上下左右的padding为0,宽度充满,高度自适应

 @Overridepublic void show() {super.show();WindowManager.LayoutParams attributes = getWindow().getAttributes();attributes.gravity = Gravity.BOTTOM;attributes.width = WindowManager.LayoutParams.MATCH_PARENT;attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;getWindow().getDecorView().setPadding(0, 0, 0, 0);getWindow().setAttributes(attributes);}

设置完以上属性之后,dialog的宽度就是充满全屏的,这里暂时没有截图 大致就是下图这个样子了

然后又在布局中加入了marginStart和marginEnd属性,就搞定了,在手机上测试也是没有什么问题了,原生的dialog有很多的问题,改着也很麻烦,推荐用超哥的dialogx https://github.com/kongzue/DialogX

 

这篇关于android dialog的沙雕问题(宽度不充满全屏)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/318877

相关文章

解决pandas无法读取csv文件数据的问题

《解决pandas无法读取csv文件数据的问题》本文讲述作者用Pandas读取CSV文件时因参数设置不当导致数据错位,通过调整delimiter和on_bad_lines参数最终解决问题,并强调正确参... 目录一、前言二、问题复现1. 问题2. 通过 on_bad_lines=‘warn’ 跳过异常数据3

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

解决RocketMQ的幂等性问题

《解决RocketMQ的幂等性问题》重复消费因调用链路长、消息发送超时或消费者故障导致,通过生产者消息查询、Redis缓存及消费者唯一主键可以确保幂等性,避免重复处理,本文主要介绍了解决RocketM... 目录造成重复消费的原因解决方法生产者端消费者端代码实现造成重复消费的原因当系统的调用链路比较长的时

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

kkFileView启动报错:报错2003端口占用的问题及解决

《kkFileView启动报错:报错2003端口占用的问题及解决》kkFileView启动报错因office组件2003端口未关闭,解决:查杀占用端口的进程,终止Java进程,使用shutdown.s... 目录原因解决总结kkFileViewjavascript启动报错启动office组件失败,请检查of

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx