android - 适配不同的机器人显示
问题描述
我应该如何将文本、按钮图像等调整到不同的屏幕?例如,使文本或图像在大屏幕和小屏幕上都具有可读性。网上有写,需要创建前缀为hdpi、mdpi等的文件夹,但这不是改编,而是简单的创建几个xml标记,从而占用额外的内存空间。我想使用百分比之类的东西还是有其他解决方案?
解决方案
我向你推荐这个库https://github.com/intuit/sdp
一个提供新大小单位的 android lib - sdp (scalable dp)。此尺寸单位随屏幕尺寸缩放。它可以帮助Android开发者支持多屏。
所有你需要的是添加它的依赖项为无文本大小使用这个
dependencies {
implementation 'com.intuit.sdp:sdp-android:1.0.6'
}
这是 XML 上的一个例子
<LinearLayout
android:id="@+id/give_us_a_review_landmine_main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/_27sdp"
android:paddingLeft="@dimen/_43sdp"
android:paddingRight="@dimen/_43sdp"
android:paddingTop="@dimen/_50sdp" >
字体大小使用这个
dependencies {
implementation 'com.intuit.ssp:ssp-android:1.0.6'
}
此示例用于使用文本大小
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Intuit"
android:textColor="@android:color/black"
android:textSize="@dimen/_40ssp"/>
推荐阅读
- python - 什么时候需要将异常对象传递给 Logger.exception
- c++ - 我们可以让 GDB 在回溯中显示非平凡的参数吗
- azure - Azure Function App 日志中的远程证书错误
- python - Python FastAPI:拥有超类模型 .dict() 还包括子类键
- c# - 需要修改子元素的默认tab顺序
- reactjs - React.js 错误:“对象作为 React 子项无效(找到:带有键 {} 的对象)。”
- javascript - VueJs - Vuetify - v-navigation-drawer 与智能手机的迷你变体
- wpf - 为什么标题没有保存在数据库中 - WPF/Telerik/RadGridView?
- c# - ArgumentException:从 FileStream 复制到 MemoryStream 时参数无效
- android - 无法使用改造将 json 数据映射到 pojo 类