Android小笔记

来源:互联网 发布:阿里云cnd 编辑:程序博客网 时间:2024/05/29 03:45

小知识点

  1. 通过图层实现操作指引
    在Activity的onCreate()中我们可以通过setContentView(layoutID)添加布局文件。其实在布局文件的根ViewGroup的getParent()可以获得外层的FramLayout,所以可以通过添加View来实现。

问题记录

1 . 编译项目aapt error exit value 1

AGPBI: {"kind":"SIMPLE","text":"D:\\AndroidWORK\\Fen\\trunk\\Fen\\Ku\\src\\main\\res\\drawable-hdpi\\w.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited","position":{},"original":"D:\\AndroidWORK\\Fen\\trunk\\Fen\\Ku\\src\\main\\res\\drawable-hdpi\\w.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited"}AGPBI: {"kind":"SIMPLE","text":"D:\\AndroidWORK\\Fen\\trunk\\Fen\\Ku\\build\\intermediates\\res\\debug\\values-xhdpi\\values.xml: Original is here. The version qualifier may be implied.","position":{},"original":"D:\\AndroidWORK\\Fen\\trunk\\Fen\\Ku\\build\\intermediates\\res\\debug\\values-xhdpi\\values.xml: Original is here. The version qualifier may be implied."}解决方法:更换其他版本的buildTool.(之前一直用21.1.1 后改为20.0.0解决的,很奇怪的问题,不知道是不是buildTool 自己的bug)

2 . 一个由UNION ALL字段不一致引起的奇怪现象

开发使用国产实体机(不得不吐槽一下),程序发生错误一闪退出,try-catch都获取不到异常。查看log:Fatal signal 11 (SIGSEGV) at 0xd1d1d1d1 (code=1)google之后一般都是多线程访问canvas和jni两种情况,跟我的实际情况没有一点点相似的地方。折腾两个小时无果,又用模拟器测试。duang~~竟然能够被try-catch了,吐血三升!

3.获取textview每行字高度来设置SpannableString中图片的高度于文字同高

private int getFountHeight(TextView tv) {    Paint paint = new Paint();    paint.setTextSize(tv.getTextSize());    Paint.FontMetrics fm = paint.getFontMetrics();    return (int) Math.ceil(fm.descent - fm.ascent);  }

4 . AS使用百度定位报错162

android {    .......    sourceSets.main {    jniLibs.srcDir 'src/main/jni' // jPush default so file in libs,here set the folder  }   ......}

5 . 判断设备是否有虚拟键以及获取虚拟键的高度

private static boolean checkDeviceHasNavigationBar(Context context) {  boolean hasNavigationBar = false;  Resources rs = context.getResources();  int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");  if (id > 0) {    hasNavigationBar = rs.getBoolean(id);  }    //检查配置是否使用默认值  try {    Class systemPropertiesClass = Class.forName("android.os.SystemProperties");    Method m = systemPropertiesClass.getMethod("get", String.class);    String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");    if ("1".equals(navBarOverride)) {      hasNavigationBar = false;    } else if ("0".equals(navBarOverride)) {      hasNavigationBar = true;    }  } catch (Exception e) {    DebugLog.e(e.toString());  }  return hasNavigationBar;}private static int getNavigationBarHeight(Context context) {  int navigationBarHeight = 0;  Resources rs = context.getResources();  int id = rs.getIdentifier("navigation_bar_height", "dimen", "android");  if (id > 0 && checkDeviceHasNavigationBar(context)) {    navigationBarHeight = rs.getDimensionPixelSize(id);  }  return navigationBarHeight;}
0 0
原创粉丝点击