首页 > 解决方案 > 适配不同的机器人显示

问题描述

我应该如何将文本、按钮图像等调整到不同的屏幕?例如,使文本或图像在大屏幕和小屏幕上都具有可读性。网上有写,需要创建前缀为hdpi、mdpi等的文件夹,但这不是改编,而是简单的创建几个xml标记,从而占用额外的内存空间。我想使用百分比之类的东西还是有其他解决方案?

标签: android

解决方案


我向你推荐这个库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"/>

推荐阅读