显示单位px和dip以及sp的区别
dip: device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA 推荐使用这个,不依赖像素。
px: pixels(像素). 不同设备显示效果相同,一般我们HVGA代表320x480像素,这个用的比较多。
pt: point,是一个标准的长度单位,1pt=1/72英寸,用于印刷业,非常简单易用;
sp: scaled pixels(放大像素). 主要用于字体显示best for textsize。
由此,根据 google 的建议,TextView 的字号最好使用 sp 做单位,而且查看
TextView
的源码可知 Android 默认使用 sp 作为字号单位。
###################################################################
关于换算(以 sp 和 pt 为例)
查看 TextView 等类的源码,可知:
case COMPLEX_UNIT_PX:
return value;
case COMPLEX_UNIT_SP:
return value * metrics.scaledDensity;
case COMPLEX_UNIT_PT:
return value * metrics.xdpi * (1.0f/72);
--------------------------
scaledDensity = DENSITY_DEVICE / (float) DENSITY_DEFAULT;
xdpi = DENSITY_DEVICE;
--------------------------
DENSITY_DEFAULT = DENSITY_MEDIUM = 160;
============================================
所以: 假设 pt 和 sp 取相同的值 1,则可设 1pt 和 1sp 之间系数为 x,
1 * DENSITY_DEVICE / 72 = x * 1 * DENSITY_DEVICE / 160 =>
x = 160 / 72 = 2.2222
也就是说在 Android 中, 1pt 大概等于 2.22sp
以上供参考,如果 UI 能够以 sp 为单位提供设计是最好的,如果设计中没有 sp
的概念,则开发人员也可以通过适当的换算取近似值。
转载内容: http://hi.baidu.com/lfcaolibin/blog/item/f3f60d1e438deefee0fe0bae.html
什么是Dip和Sp
过去,程序员通常以像素为单位设计计算机用户界面。例如,定义一个宽度为300像素的表单字段,列之间的间距为5个像素,图标大小为16×16像素 等。这样处理的问题在于,如果在一个每英寸点数(dpi)更高的新显示器上运行该程序,则用户界面会显得很小。在有些情况下,用户界面可能会小到难以看清 内容。
与分辨率无关的度量单位可以解决这一问题。Android支持下列所有单位。
px(像素):屏幕上的点。
in(英寸):长度单位。
mm(毫米):长度单位。
pt(磅):1/72英寸。
dp(与密度无关的像素):一种基于屏幕密度的抽象单位。在每英寸160点的显示器上,1dp = 1px。
dip:与dp相同,多用于android/ophone示例中。
sp(与刻度无关的像素):与dp类似,但是可以根据用户的字体大小首选项进行缩放。
为了使用户界面能够在现在和将来的显示器类型上正常显示,建议大家始终使用sp作为文字大小的单位,将dip作为其他元素的单位。当然,也可以考虑使用矢量图形,而不是用位图
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
function onDeviceReady() {
// 注册回退按钮事件监听器
document.addEventListener("backbutton", onBackKeyDown, false); //返回键
}
function onConfirm(button) {
//alert('You selected button ' + button);
if(button==1) navigator.app.exitApp(); //选择了确定才执行退出
}
// Show a custom confirmation dialog
//
function onBackKeyDown() {
navigator.notification.confirm(
'按确定退出程序!', // message
onConfirm, // callback to invoke with index of button pressed
'确定要退出程序吗?', // title
'确定,取消' // buttonLabels
);
}
查看可切换的分支
cd .repo/manifests
git branch -a | cut -d / -f 3
以 gingerbread-release 分支为例
repo init -b android-4.1.2_r1
repo sync (not needed if your local copy is up to date)
repo start android-4.1.2_r1 --all
查看当前的分支
repo branches
error: external/valgrind/: platform/external/valgrind checkout d5d3abcc16492e823e09201a56a7d8c991e194d9
error: prebuilt/: platform/prebuilt checkout 4046d154f6b6d0722a7c1199e4be9322531cb3ca
wv@LiXia_PC ~/Android-4.0.0_r1
$ ~/bin/repo branches
* android-4.1.2_r1 | not in bionic, external/valgrind, prebuilt
报错了,没有全部转完!
查看当前所有分支:git branch -a
把所有的库切换分支: repo forall -c git checkout branch_name
删除所有库的某个分支: repo forall -c git branch -D branch_name$ ~/bin/repo sync -j1 remote: Counting objects: 597, done remote: Finding sources: 100% (4/4) remote: Total 4 (delta 2), reused 4 (delta 2) Unpacking objects: 100% (4/4), done. From https://android.googlesource.com/platform/build 923ac1a..a1fd8e4 master -> aosp/master Fetching projects: 100% (293/293), done. info: A new version of repo is available object 45d21685b93f80b67239849b2d2cfe6b217e335a type commit tag v1.12.2 tagger Shawn Pearce <sop@google.com> 1362159402 -0800 repo 1.12.2 error: cannot run gpg: No such file or directory error: could not run gpg. error: could not verify the tag 'v1.12.2' warning: Skipped upgrade to unverified version Syncing work tree: 0% (2/293) error: Your local changes to the following files would be overwritten by checkout: libc/kernel/common/linux/netfilter/xt_CONNMARK.h libc/kernel/common/linux/netfilter/xt_MARK.h libc/kernel/common/linux/netfilter_ipv6/ip6t_HL.h Please, commit your changes or stash them before you can switch branches. Aborting Syncing work tree: 55% (162/293) error: Your local changes to the following files would be overwritten by checkout: main/docs/html/FAQ.html Please, commit your changes or stash them before you can switch branches. Aborting Syncing work tree: 90% (264/293) error: Your local changes to the following files would be overwritten by checkout: linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter/xt_CONNMARK.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter/xt_DSCP.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter/xt_MARK.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter/xt_TCPMSS.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_CONNMARK.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_DSCP.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_ECN.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_MARK.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_TCPMSS.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_TOS.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv4/ipt_TTL.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv6/ip6t_HL.h linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/include/linux/netfilter_ipv6/ip6t_MARK.h Please, commit your changes or stash them before you can switch branches. Aborting Syncing work tree: 100% (293/293), done. error: bionic/: platform/bionic checkout f57514eb59747171f55cd9b4abb064f1a474d5ee error: external/valgrind/: platform/external/valgrind checkout d5d3abcc16492e823e09201a56a7d8c991e194d9 error: prebuilt/: platform/prebuilt checkout 4046d154f6b6d0722a7c1199e4be9322531cb3ca好像没有成功更新
Fetching projects: 100% (293/293), done.
fatal: bad config file line 1 in .git/config
Traceback (most recent call last):
File "/home/wv/android/source/.repo/repo/main.py", line 414, in <module>
_Main(sys.argv[1:])
File "/home/wv/android/source/.repo/repo/main.py", line 390, in _Main
result = repo._Run(argv) or 0
File "/home/wv/android/source/.repo/repo/main.py", line 138, in _Run
result = cmd.Execute(copts, cargs)
File "/home/wv/android/source/.repo/repo/subcmds/sync.py", line 630, in Execute
project.Sync_LocalHalf(syncbuf)
File "/home/wv/android/source/.repo/repo/project.py", line 1086, in Sync_LocalHalf
lost = self._revlist(not_rev(revid), HEAD)
File "/home/wv/android/source/.repo/repo/project.py", line 2006, in _revlist
return self.work_git.rev_list(*a, **kw)
File "/home/wv/android/source/.repo/repo/project.py", line 2155, in rev_list
p.stderr))
error.GitError: platform/bionic rev-list ('^f57514eb59747171f55cd9b4abb064f1a474d5ee', 'HEAD', '--'): fatal: bad config file line 1 in .git/config
wv@wv-ThinkPad-SL:~/android/source$