[TOC]
1 android TypedValue.applyDimension()的作用
Android自带的单位转化函数。
|
|
这里COMPLEX_UNIT_SP是原始单位,20是数值,也就是20sp,输出px数值。
这里的DisplayMetrics
也可以这样获得:
|
|
2 AtomicInteger的用途
|
|
AtomicInteger提供原子操作来进行Integer的使用,通过线程安全的方式操作加减,因此十分适合高并发情况下的使用。但是使用volatile将使得VM优化失去作用,导致效率较低,所以要在必要的时候使用。
3 Rect和RectF之间的区别
- Rect的参数为int类型,而RectF的参数类型为float类型,从这一点上来看,RectF的精度更高一些。
- 绘制曲线时用RectF。
- 方法不一致。
4 @GuardedBy(lock)
描述哪个状态变量被哪个锁保护着,以及哪个锁保护这些变量的信息
5 SystemClock.sleep()方法与Thread.sleep()方法的区别
SystemClock.sleep()
不需要考虑InterruptedException
,而Thread.sleep()
中可能会出现InterruptedException
,容易导致假死奔溃。
|
|
查看源码发现SystemClock.sleep()
也是调用的Thread.sleep()
,只是将异常捕获住了。
6 JDK7二进制整数以及下划线分隔符新特性
JDK7提供了下划线分隔符,能够按照自己的习惯进行数字的分割,例如:int b = 1_2312_3131;
很容易知道这是1亿2312万3131。
7 SystemClock.uptimeMillis()、SystemClock.elapsedRealtime()和 System.currentTimeMillis()
- SystemClock.uptimeMillis()表示系统开机到当前的时间总数,单位是毫秒,但是,当系统进入深度睡眠(CPU休眠、屏幕休眠、设备等待外部输入)时间就会停止,但是不会受到时钟缩放、空闲或者其他节能机制的影响。
- SystemClock.elapsedRealtime()表示系统开机到当前的时间总数,单位是毫秒。它包括了系统深度睡眠的时间。这个时钟是单调的,它保证一直计时,即使CPU处于省电模式,所以它是推荐使用的时间计时器。
- System.currentTimeMillis()获取的是系统的时间,可以使用SystemClock.setCurrentTimeMillis(long millis)进行设置。如果使用System.currentTimeMillis()来获取当前时间进行计时,应该考虑监听ACTION_TIME_TICK, ACTION_TIME_CHANGED 和 ACTION_TIMEZONE_CHANGED这些广播ACTION,如果系统时间发生了改变,可以通过监听广播来获取。
8 RecycleView中的GridLayoutManager.SpanSizeLookup
参考RecyclerView 中setSpanSizeLookup 解释
|
|
这里定义了一个双列的表格管理器。
|
|
这里按位置判断一行显示单列还是双列。
9 BuildConfig.DEBUG
|
|
注意BuildConfig的来源包有几个的,别导错了。
10 setWillNotDraw和setFillViewport
参考:http://blog.csdn.net/chuyouyinghe/article/details/48787473
setFillViewport(true)
It must be set to ScrollView and has the following efect : when set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.
setWillNotDraw(false)
If this view doesn’t do any drawing on its own, set this flag to allow further optimizations. By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(Canvas) you should clear this flag.
比如这个库
|
|
11 android popupwindow showAsDropDown 为何offsetx无效,offsety有效
showAsDropDown显示的点是以anchorView左下角点为参照点.
改为
|
|
12 Android Support Library 23.2 特性
Vector Drawable以及Animated Vector Drawables
第一步:
|
|
第二步:
准备好svg图片,Android Studio带有转换功能。
第三步:
|
|
13 android:clipChildren和android:clipToPadding
clipToPadding:控件的绘制区域是否绘制到padding为止,true表示不会会绘制到padding中,默认值为true。
clip是修剪的意思。
参考:http://www.jianshu.com/p/2cbc9c12d221
clipChildren:是否限制子View在其范围内,我们将其值设置为false后那么当子控件的高度高于父控件时也会完全显示,而不会被压缩
Defines whether a child is limited to draw inside of its bounds or not. This is useful with animations that scale the size of the children to more than 100% for instance. In such a case, this property should be set to false to allow the children to draw outside of their bounds. The default value of this property is true.
注意:
- 只需在根节点设置android:clipChildren为false即可,默认为true,注意:一定是在布局文件的根节点设置,否则不起作用
- 可以通过android:layout_gravity控制超出的部分如何显示
参考:
- http://blog.csdn.net/qq_17766199/article/details/53726062
- http://blog.csdn.net/flymoon1201/article/details/44646473
14 Android中一些你可能没注意的小效果实现
scrollview滚动条颜色,edittext光标之类的。
http://www.jianshu.com/p/f361123b0963
15 滚动条
设置滑动到顶部和底部的背景或颜色:
|
|
设置滑动到边缘时无效果模式:
|
|
设置滚动条不显示:
|
|
整体设置:
|
|
滚动条的样式和位置
|
|
insideOverlay:默认值,表示在padding区域内并且覆盖在view上
insideInset:表示在padding区域内并且插入在view后面
outsideOverlay:表示在padding区域外并且覆盖在view上,推荐这个
outsideInset:表示在padding区域外并且插入在view后面
16 隐藏导航栏和状态栏
隐藏导航栏
|
|
隐藏状态栏
|
|
或者
|
|
隐藏标题栏
|
|
或者
|
|
17 获取标题栏、状态栏、导航栏高度
标题栏
|
状态栏
|
|
导航栏
|
|
18 TextView去除默认的上下padding
|
|
19 顺畅地取消动画效果
|
|
Chales在Android7.0上不能抓包的问题
http://blog.csdn.net/u011045726/article/details/76064048
安卓上要装两个证书:
- charles Help/SSL Proxying/Save Charles Root Certificate
把这个证书传到手机上,找到安全设置,从设备安装,安装这个证书。 - charles Help/SSL Proxying/Install Charles Root Certificate on a Mobile Device or Remote Browser