安卓屏幕适配方案,只需一个步骤即可使用,也可根据自己项目设计图画布大小和像素尺寸实时精准适配,适配所有市面上各种大小不一的安卓手机屏幕,特点是可以直接在Android studio的XML编辑器中直接预览不同手机屏幕的适配效果,提高工作效率,且完全不会有性能问题,极易上手

<Button
android:layout_width="match_parent"
android:layout_height="@dimen/widget_size_45"
android:layout_marginTop="@dimen/widget_size_10"
android:textSize="@dimen/font_size_10"/>
/**
* 密度因子
*/
int density;
/**
* 屏幕相对宽度
*/
int width;
/**
* 1.根据UI画布大小比例进行换算,假设UI图分辨率为1334x750
* 设备默认缩放因子密度为 density = 320 / 160 , 即 density = 2
* 宽度 width = 750
* 可选项,根据你实际的UI设计图来定义
*/
density = 2;
width = 750 / density;
/**
* 2.根据UI画布大小比例进行换算,假设UI图分辨率为1080x1920
* 高分率缩放因子密度一般为 density = 80 / 160 , 即 density = 3
* 宽度 width = 1080
* 可选项,根据你实际的UI设计图来定义
*/
density = 3;
width = 1080 / density;
/**
* 执行生成适配的dimens.xml文件
*/
gen(width);


如果dimens.xml中没有你们想要的尺寸,打开values文件下的dimens.xml文件中添加即可,再执行main函数生成相对应尺寸的即可

一分钟了解Android屏幕 ldpi mdpi hdpi xhdpi
如果你是按照1920 x 1080 的设计图的尺寸开发UI,那么在 2160 x 1080 的全面屏手机中会出现高度偏差的问题
即按照设计图的比例开发的UI与需要适配的手机屏幕比例必须一致,否则就会出现类似高度偏差的问题。
解决方法:
根据需要适配的比例进行高度的手动换算
使用 layout_weight 权重属性灵活定义高度
Copyright 2016 cheng2016,Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
—
$ claude mcp add AndroidUIAdapter \
-- python -m otcore.mcp_server <graph>