Increase the font size based on the size of the device

前端 未结 7 640
天命终不由人
天命终不由人 2020-12-14 16:53

I planned to use different font size for the textview on different device size so as to make the letters legible. I have already decided not to use different layouts for dif

相关标签:
7条回答
  • 2020-12-14 16:59

    For font sizes use scale pixels (sp). Android will scale the font size accordingly depending on the device density. Above posts have a better explanation and the reasoning.

    0 讨论(0)
  • 2020-12-14 17:07

    Yes, this approach is flawed. Android devices have different sizes, but they can also have very different densities as well.

    enter image description here

    You should just be following the Android design best practices.

    enter image description here

    They're actually very well thought out. Why would you want to reinvent the wheel?

    0 讨论(0)
  • 2020-12-14 17:07

    Try this, Add this attribute in your xml. It will adjust textsize based on screensize try it.

     style="@android:style/TextAppearance.DeviceDefault.Medium"
    
    0 讨论(0)
  • 2020-12-14 17:20
        String s= "hello";
        TextView tv= (TextView) findViewById(R.id.tv);
        Spannable span = new SpannableString(s);
        span.setSpan(new RelativeSizeSpan(5f), 0, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(span);
    

    Based on screen size change 5f to whatever you want.

    http://developer.android.com/guide/practices/screens_support.html. Check the topic under heading Best Practices.

    0 讨论(0)
  • 2020-12-14 17:21

    for this issue I am using following library in so many projects and believe this is fantastic. No need to worry about screens. But again you need to create separate layouts for tabs.

    https://github.com/intuit/sdp

    0 讨论(0)
  • 2020-12-14 17:21

    For API 26 and higher

    <?xml version="1.0" encoding="utf-8"?>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:autoSizeTextType="uniform" />
    

    Source:https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview

    0 讨论(0)
提交回复
热议问题