/**
* 获取最佳预览大小
*
* @param parameters 相机参数
* @param screenResolution 屏幕宽高
* @return
*/
private Point getBestCameraResolution(Camera.Parameters parameters, Point screenResolution) {
float tmp;
float mindiff = 100f;
float x_d_y = (float) screenResolution.x / (float) screenResolution.y;
Size best = null;
List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
for (Size s : supportedPreviewSizes) {
tmp = Math.abs(((float) s.height / (float) s.width) - x_d_y);
if (tmp < mindiff) {
mindiff = tmp;
best = s;
}
}
return new Point(best.width, best.height);
}
/**
* 获取屏幕宽度和高度,单位为px
*
* @param context
* @return
*/
public static Point getScreenMetrics(Context context) {
DisplayMetrics dm = context.getResources().getDisplayMetrics();
return new Point(dm.widthPixels, dm.heightPixels);
}
作者:root
Android屏幕适配
创建软链接(符号链接)
Windows
mklink /d link source
Linux
ln -s source link
Android使用ItemTouchHelper实现RecyclerView的拖拽排序
Android使用POI读取Excel(XLS和XLSX)
1.添加依赖
// Excel implementation 'org.apache.poi:poi:3.17' implementation 'org.apache.poi:poi-ooxml:3.17' implementation 'org.apache.xmlbeans:xmlbeans:3.1.0' implementation 'stax:stax:1.2.0'
2.在程序中使用
private void readExcel(String fileName) {
try {
InputStream inputStream = new FileInputStream(fileName);
Workbook workbook;
if (fileName.endsWith(".xls")) {
workbook = new HSSFWorkbook(inputStream);
} else if (fileName.endsWith(".xlsx")) {
workbook = new XSSFWorkbook(inputStream);
} else {
return;
}
Sheet sheet = workbook.getSheetAt(0);
int rowsCount = sheet.getPhysicalNumberOfRows();
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
for (int r = 0; r < rowsCount; r++) {
Row row = sheet.getRow(r);
CellValue v0 = formulaEvaluator.evaluate(row.getCell(0));
CellValue v1 = formulaEvaluator.evaluate(row.getCell(1));
Log.i("Excel", "readExcel: " + v0.getStringValue() + "," + v1.getStringValue());
}
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Android 依赖冲突(Gradle查看依赖树)
节选自:Android依赖冲突解决方法
依赖分析
查看依赖关系需要用到的命令为:
gradlew :[module_name]:dependencies
如需分析工程中app这个module的依赖关系行命令则为:
gradlew :app:dependencies
如果你想把依赖关系输出到文件中,则可以使用以下命令:
gradlew :[module_name]:dependencies > [output_file]
例如将app module的依赖关系输出到dependence.txt文件中:
gradlew :app:dependencies > dependence.txt
简化版Gradle查看依赖树命令(Gradle查看依赖树解惑)
gradlew :app:dependencies --configuration releaseCompileClasspath > dependence.txt
Android: Camera相机开发详解
Java设计模式透析
Android图片加载框架最全解析
Glide使用总结
首先,添加依赖
implementation 'com.github.bumptech.glide:glide:4.11.0'
之后添加访问网络权限
<uses-permission android:name="android.permission.INTERNET" />
一、常用的方法
1、加载图片到imageView
Glide.with(this).load(url).into(imageView);
2、加载带有占位图
Glide.with(this).load(url).placeholder(R.drawable.loading).into(imageView);
3、加载指定大小的图片
Glide.with(this)
.load(url)
.placeholder(R.drawable.loading)
.override(100, 100)//指定图片大小
.into(imageView);