笔记(网上收集)

1.
ViewCompat.canScrollVertically(view, -1)//是否能向下滚动
ViewCompat.canScrollVertically(view, 1)//是否能向上滚动

private VelocityTracker mVelocityTracker;//速率

mVelocityTracker = VelocityTracker.obtain();//初始化

mVelocityTracker.addMovement(ev);//事件添加进去

mVelocityTracker.computeCurrentVelocity(1000);
float yVelocity = mVelocityTracker.getYVelocity();//获取Y轴上的瞬时速度

mVelocityTracker.clear();
mVelocityTracker.recycle();

2.

在写布局时,ListView的高度android:layout_height设置固定值或者match_parent
如果设置wrap_content,会出现 getView的多次调用

这里写图片描述

    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

3.

ListView的item中有button,checkbox等时,点击条目点击事件优先分配给button,
导致点击item失效,此时可给item的跟布局设置以下属性

android:descendantFocusability="blocksDescendants"

4.

Pair pair = new Pair(“号”, 1);//可以存储两个任意的Object
Pair pair =Pair.create(“号”, 1);

5

android:duplicateParentState=”true”,让子View跟随其Parent的状态,如pressed等。

6.

应该可以做金额的显示隐藏

if (tv.getText().length() % 2 == 0) {
                    et.setTransformationMethod(new PasswordTransformationMethod());
                } else {
                    et.setTransformationMethod(null);
                }

7.

apache提供的一系列jar包:commons-lang.jar,commons-collections.jar,commons-beanutils.jar等,里面很多方法可能是你曾经用几十几百行代码实现过的,但是执行效率或许要差很多,比如:ArrayUtils,StringUtils……;

作者:StephenLee
链接:http://www.zhihu.com/question/33636939/answer/57171337
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

8.
刷新时用到,显示几分钟前

Log.e("tag", DateUtils.getRelativeTimeSpanString(System.currentTimeMillis() - 100000));

打印日志:
07-13 17:33:41.842 17688-17688/com.hou.listview E/tag: ===1 分钟前

9.
用pathMeasure.getSegment时,在api19及以下,需要在get之前添加drawPath.rLineTo(0,0);否则不会正常绘制

drawPath.reset();
drawPath.rLineTo(0,0);
pathMeasure.getSegment(0, distance * pathMeasure.getLength(), drawPath, true);

10.
Vector动画时
app-gradle中添加支持库

android {
    defaultConfig {
        ...

        vectorDrawables.useSupportLibrary = true//版本 L(21) 以下需要
    }
 }

java中使用AnimatedVectorDrawableCompat ,N以上使用AnimatedVectorDrawable

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    AnimatedVectorDrawable drawable = (AnimatedVectorDrawable) image.getDrawable();
     drawable.start();
 } else {
     AnimatedVectorDrawableCompat drawable = (AnimatedVectorDrawableCompat) image.getDrawable();
     drawable.start();
 }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章