一些小知识点

来源:互联网 发布:舟山淘宝代运营诈骗案 编辑:程序博客网 时间:2024/05/21 17:14

1.progressbar的颜色受style文件控制,具体是由主style标签下的colorAccent的颜色决定的

2,integer.valueof()内部调用parseint(),valueof返回的是integer对象,parseint返回的是int数据

3.sdk升级到7.0后,AES加密时用到的secureRandom的实例化有所不同,具体看代码:

public class CryptoProvider extends Provider {    /**     * Constructs a provider with the specified name, version number,     * and information.     *       a description of the provider and its services.     */    protected CryptoProvider() {        super("Crypto", 1.0, "HARMONY (SHA1 digest; SecureRandom; SHA1withDSA signature)");        put("SecureRandom.SHA1PRNG","org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl");        put("SecureRandom.SHA1PRNG ImplementedIn", "Software");    }}
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){    sr = SecureRandom.getInstance("SHA1PRNG",new CryptoProvider());}else {    sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");}

4.ViewAnimationUtils,android5.0以后出现的一个类,该类只有一个方法,createCircularRevael(),可以帮助我们实现view变园的操作

5.canvas.drawArc的参数中有一个boolean类型的参数,usecenter,如果设为true,则会画出从圆心开始的两条半径,组成一个扇形,如果为false,则单纯画弧线

6.求出这个point,然后canvas.drawtext的方法中使用这个point的x,y就可以达到文字在自定义控件中居中的显示了

//文字居中的通用方法private Point getTextPointInView(Paint textPaint, String textDesc, int w, int h) {    if (null == textDesc) return null;    Point point = new Point();    int textW = (w - (int) textPaint.measureText(textDesc)) / 2;    Paint.FontMetrics fm = textPaint.getFontMetrics();    int textH = (int) Math.ceil(fm.descent - fm.top);    point.set(textW, h / 2 + textH / 2 - textH / 4);    return point;}

7.关于text的几条线(使用的是xyczero的博客图片)


以baseline为基准,ascent和top都为负,descent和bottom为正,所以,文字的高度一般可以descent-ascent来计算

8,今天在写radiiobutton时,碰到一个问题,在xml里定义好radiobutton,它被包裹在一个背景是白色的LinearLayout里,然后radiobutton的文字死活显示不出来,查了各种原因,都不行,最后发现没有给text设置颜色,跟到源码里,在textview里发现这样一段代码,瞬间明白怎么回事:


如果没有给它设置颜色,默认是白色的,然后又在白色的LinearLayout里,所以就显示不出来了。好尴尬,之前都没注意到

9,include,可以给它设置ID,但是前提是先给他设置width和height,这个在用到visibility时很有用

10,今天发现一个问题,之前一直没有注意。在APP的启动页要做一些判断什么的,我把他们写在了onresume里,然后发现后面的欢迎页面会出现两次,后来想到是因为权限判断的问题,权限弹框的谈起会导致调用多次onresume。。。。。。

11.getMeasureWidth()方法在measure()过程结束后就可以获取到了,而getWidth()方法要在layout()过程结束后才能获取到。getMeasureWidth()方法中的值是通过setMeasuredDimension()方法来进行设置的,而getWidth()方法中的值则是通过layout(left,top,right,bottom)方法设置的。

12.clipdrawable 

<clip xmlns:android="http://schemas.android.com/apk/res/android"    android:clipOrientation="horizontal"    android:drawable="@drawable/pro_sel"    android:gravity="left" />

可以用来做进度条

13.scroller的两个方法,startscroll,start scrolling by providing a starting point,the distance to travel and the duration of the scroll

fling,start scrolling based on a fling gesture. The distance travelled will depend on the initial velocity of the fling.

startscroll是有起始位置的,而fling,是从初速度开始判断的,没有起始位置

原创粉丝点击