TextView textSize 文字大小
TextView,很常见的控件。关于文字大小的方法有:
android.widget.TextView#getTextSize 返回值的单位是PX
/**
* @return the size (in pixels) of the default text size in this TextView.
*/
@ViewDebug.ExportedProperty(category = "text")
public float getTextSize() {
return mTextPaint.getTextSize();
}
android.widget.TextView#getScaledTextSize 返回值单位是SP
/**
* @return the size (in scaled pixels) of thee default text size in this TextView.
* @hide
*/
@ViewDebug.ExportedProperty(category = "text")
public float getScaledTextSize() {
return mTextPaint.getTextSize() / mTextPaint.density;
}
android.widget.TextView#setTextSize(float) 参数的单位是SP
/**
* Set the default text size to the given value, interpreted as "scaled
* pixel" units. This size is adjusted based on the current density and
* user font size preference.
*
* @param size The scaled pixel size.
*
* @attr ref android.R.styleable#TextView_textSize
*/
@android.view.RemotableViewMethod
public void setTextSize(float size) {
setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
}
android.widget.TextView#setTextSize(int, float) 参数的单位是两个,第一个是单位,第二个是数值
/**
* Set the default text size to a given unit and value. See {@link
* TypedValue} for the possible dimension units.
*
* @param unit The desired dimension unit.
* @param size The desired size in the given units.
*
* @attr ref android.R.styleable#TextView_textSize
*/
public void setTextSize(int unit, float size) {
Context c = getContext();
Resources r; if (c == null)
r = Resources.getSystem();
else
r = c.getResources(); setRawTextSize(TypedValue.applyDimension(
unit, size, r.getDisplayMetrics()));
}
总结:
- get方法,注意返回值的单位
- set方法,注意参数的单位
补充
在自定义控件中使用自定义属性时,经常需要使用java代码获取在xml中定义的尺寸,相关有以下三个函数
- getDimension()
- getDimensionPixelOffset()
- getDimensionPixelSize()
它们三个返回值的单位都是:PX
TextView textSize 文字大小的更多相关文章
- Android TextView 实现文字大小不同和文字颜色不同
效果图如下: 关键代码如下: StringBuffer sb = new StringBuffer(); if(day > 0) { sb.append("<a href=\&q ...
- ProgressDialog(四)——更改系统自带ProgressDialog文字大小
MainActivity如下面: package com.example.ttt; import android.app.Activity; import android.app.ProgressDi ...
- 自定义界面上绘制Text,可通过拖动控制文字大小及其位置
项目地址 最近项目上有个需求,需要在一块区域中显示文字,这块区域可以拖动,也可以通过拖拽右下角来改变大小,里面的文字大小要根据区域的大小进行自适应.刚开始觉得这个需求不难,只需要一个TextView就 ...
- 【Android初级】使用TypeFace设置TextView的文字字体(附源码)
在Android里面设置一个TextView的文字颜色和文字大小,都很简单,也是一个常用的基本功能.但很少有设置文字字体的,今天要分享的是通过TypeFace去设置TextView的文字字体,布局里面 ...
- UIButton修改文字大小问题
一.问题描述 通过UIButton对象font属性设置文字大小,却发现该属性在2.0.3.0就已经被废弃,ios不建议使用. 图1-1:点出UIButton对象的font属性提示被废弃 图1-2:UI ...
- 使用DirectWrite测量Direct2D文字大小
转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 最近在使用Direct2D和DirectWrite写引擎,在引擎中需要实现文本标签控件.但是文本标签的尺寸最好不 ...
- html,CSS文字大小单位px、em、pt的关系换算
html,CSS文字大小单位px.em.pt的关系换算 这里引用的是Jorux的“95%的中国网站需要重写CSS”的文章,题目有点吓人,但是确实是现在国内网页制作方面的一些缺陷.我一直也搞不清楚px与 ...
- 响应式十日谈第一日:使用 rem 设置文字大小
上面回顾: 在序言中我们已经提到了响应式的一些基本理念,比如: 响应式网页不仅仅是响应不同类型的设备,而且需要响应不同的用户需求.响应式的初衷是为了让信息更好的传递交流,让所有人无障碍的获取信息,同时 ...
- 解决android自带textview右侧文字不能对齐的问题
package com.sixin.view; import android.content.Context; import android.graphics.Canvas; import andro ...
随机推荐
- 利用KVC实现无需协议的委托模式
在<精通iOS开发>一书中看到的技巧.假设BIDTaskListController是一个列表,点击列表上的一项将会导航到BIDTaskDetailController,在BIDTaskD ...
- java之Set源代码浅析
Set的接口和实现类是最简单的,说它简单原因是由于它的实现都是基于实际的map实现的. 如 hashSet 基于hashMap,TreeSet 基于TreeMap,CopyOnWriteArraySe ...
- android专栏
Android之Activity(8) Android之Adapter(1) Android之ContentProvider(1) Android之Handler(4) Android之JSON(2) ...
- if...else if...else
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace prog ...
- oracle 计算两个时间之间的月份差,相差几个星期,相差多少天
相差多少天: sysdate-to_date('1991-01-01','YYYY-MM-DD'))<7 and (sysdate-to_date('1991=01=01','YYYY-MM ...
- 如何分割(split)string字符串
使用String#split()方法 如下所示: String string = "004-034556"; String[] parts = string.split(" ...
- JSP 和 Servlet 有哪些相同点和不同点, 他们之间的联系是什么?
jsp和servlet的区别和联系:1.jsp经编译后就变成了Servlet.(JSP的本质就是Servlet,JVM只能识别java的类,不能识别JSP的代码,Web容器将JSP的代码编译成JVM能 ...
- Android应用开发基础篇(5)-----Handler与多线程
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/19/2358155.html 一.概述 Handler这个类主要用来发送和处理消息的.它有多个发 ...
- mysql server5.6.28 修改数据目录
1.查看配置文件 mysql --help | grep my.cnf 列出使用哪个配置文件(顺序推) 2.service mysql stop 3.创建新目录 mkdir /data 4.迁移之前的 ...
- Java中Calender引用类型
某些时候需要使用深拷贝: Calendar startTime = (Calendar) this._paramModel.getStartTime().clone(); 这样对startTime.a ...