Increase the font size based on the size of the device

前端 未结 7 642
天命终不由人
天命终不由人 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 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.

提交回复
热议问题