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();
}