Project Experience
- 關(guān)于觸屏的問(wèn)題
最小的觸屏距離判斷是否滑動(dòng)
ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfiguration.get(getContext()))
觸發(fā)移動(dòng)事件的最短距離,如果小于這個(gè)距離就不觸發(fā)移動(dòng)控件蚯斯,如viewpager就是用這個(gè)距離來(lái)判斷用戶是否翻頁(yè)
- 關(guān)于內(nèi)存問(wèn)題
變量的使用
HashMap : 盡量使用 WeakHashMap
List:盡量用 SparseArrayList
context 和 view 內(nèi)存釋放問(wèn)題
除了在Activity添加如下釋放方法薄风。更重要的是變量?jī)?nèi)部類和靜態(tài)類要用弱了引用
----------------------------------------------
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(new ContextWrapper(newBase) {
@Override
public Object getSystemService(String name) {
if (Context.AUDIO_SERVICE.equals(name)){
return getApplicationContext().getSystemService(name);
}
return super.getSystemService(name);
}
});
}
----------------------------------------------
關(guān)于相關(guān)問(wèn)題請(qǐng)參照
- 關(guān)于studio 打包問(wèn)題
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
java.io.IOException: Please correct the above warnings first.
解決方案
defaultConfig {
multiDexEnabled true
}
- 判斷手機(jī)是否root
private final static int kSystemRootStateUnknow = -1;
private final static int kSystemRootStateDisable = 0;
private final static int kSystemRootStateEnable = 1;
private static int systemRootState = kSystemRootStateUnknow;
public static boolean isRootSystem() {
if (systemRootState == kSystemRootStateEnable) {
return true;
} else if (systemRootState == kSystemRootStateDisable) {
return false;
}
File f = null;
final String kSuSearchPaths[] = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/"};
try {
for (int i = 0; i < kSuSearchPaths.length; i++) {
f = new File(kSuSearchPaths[i] + "su");
if (f != null && f.exists()) {
systemRootState = kSystemRootStateEnable;
return true;
}
}
} catch (Exception e) {
}
systemRootState = kSystemRootStateDisable;
return false;
}
}
gradle 一致卡在那里編譯
原因某個(gè)鏈接連不上,這個(gè)是主要原因
./gradlew build --debug
到項(xiàng)目目錄下拍嵌,用上述命令遭赂,去排查下
一般我們有時(shí)候會(huì)要做防止快速重復(fù)點(diǎn)擊,用別人框架又怕又坑横辆,那么自己封裝一下
可以了靈活應(yīng)用撇他,既可以封裝成一個(gè)Listener,也可自己在特定地方添加
public abstract class NoDoubleClickListener implements OnClickListener {
public static final int MIN_CLICK_DELAY_TIME = 1000;
private long lastClickTime = 0;
@Override
public void onClick(View v) {
long currentTime = Calendar.getInstance().getTimeInMillis();
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
lastClickTime = currentTime;
onNoDoubleClick(v);
}
}
}