1、自定义Toolbar布局的时候左边始终留有一小段空白,就像这样:
Google了一下,发现很多答案是这样:
引入:
xmlns:app="http://schemas.android.com/apk/res-auto"
然后利用:
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
我试了试,不管怎么弄都没用,即使偶尔有用,也只在5.0上有效,5.0以下一样留有空白。
真正有效的操作是这样:
首先在style.xml中定义新的style,用于toolbar的theme,如下:
<style name="ToolbarTheme" parent="Widget.AppCompat.Toolbar">
<!--注意,两个都得写,不然没效果-->
<item name="contentInsetStart">0dp</item>
<item name="contentInsetLeft">0dp</item>
</style>
然后在Application使用的AppTheme中使用起来,如下:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
//...
<item name="toolbarStyle">@style/ToolbarTheme</item>
</style>
这样,Toolbar左边的空白就没有了。而且兼容2.x-6.0的机器。
2、 从其他地方拷贝代码到Android Studio中报错:
非法字符: '\ufeff'
原因是拷贝过来的代码文件编码是UTF-8+BOM的,而项目是UTF-8的。
解决方法是将要拷贝的代码文件用文本编辑器打开并保存为UTF-8格式即可。
3、 导入几张PNG图片后项目报错:
AAPT err(Facade for 1867677377): libpng error: Not a PNG file
Error:Execution failed for task ':app:mergeDebugResources'.
> Some file crunching failed, see logs for details
原因是导入的图片中有图片不是PNG格式(虽然我们命名为XXX.PNG)。
解决方法就是将图片用图片编辑工具打开,然后保存为PNG格式的就可以了。
4、 使用Picasso加载本地图片加载不出来。
原因是在Picasso2.5.2之后,要加载本地图片需要将file作为load()方法的参数,形如:
Picasso.with(getActivity()).load(new File(imagePath)).fit().into(vh.ivImage);
5、 在实现ListView多种布局的ItemView的功能时报错:
java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6739)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1275)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java: