简体   繁体   中英

Android how can I reduce the text size based on screen size (and NOT density)

I've got a simple view with some text on it, and all I want to do is come up with a good way of adjusting the text size and padding for smaller devices, my issue though is that I don't want to consider density, just the screen size itself. The idea is to make the apps look the same between a small and large device (including padding etc.)

I've seen a lot of posts about creating value resource directories with qualifiers but this hasn't worked, as any small device with a high DP gets the padding and text size of a larger device.

For a simple example, I want the text size to be 17sp on a Pixel 3 XL and be 14sp on a Nexus 5, but there just doesn't seem like a way to do this because they have similar pixel densities even though they are vastly different in actual screen size. Am I missing something??

only one way to set dynamical change text size without density use android default font size like this

style="@android:style/TextAppearance.DeviceDefault.Small"
style="@android:style/TextAppearance.DeviceDefault.Medium"
style="@android:style/TextAppearance.DeviceDefault.Large" 


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    style="@android:style/TextAppearance.DeviceDefault.SearchResult.Title"
    android:text="Hello"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM