Android开发中常见细节问题之我见

来源:互联网 发布:淘宝迟迟不发货骗局 编辑:程序博客网 时间:2024/06/06 09:06

1、swipebackLayout滑动返回黑屏和home键app闪烁的冲突

<item name="android:windowIsTranslucent">true</item>

设置为true时,滑动返回正常,home键会闪烁;反之
设置为false时,滑动返回黑屏,home键正常。

2、Glide加载图片失败提示和加载中gif动画的冲突

 Glide.with(context)                .load(url)                .thumbnail(Glide.with(context).load(R.drawable.image_loading))                .into(imageView);

以上是显示加载中gif动画

Glide.with(context).load(uri).asBitmap().into(new SimpleTarget<Bitmap>(width, height) {     @Override     public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {         // add image to the imageView here          imageView.setImageBitmap(resource);     }     @Override     public void onLoadFailed(Exception e, Drawable errorDrawable) {         // you are given the error drawable         super.onLoadFailed(e, errorDrawable);                        imageView.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.image_error));     }});

这是显示加载失败图片

以上两者无法组合起来使用,甚是无语,而api自带的error方法也不起作用

Q:桌面图标上可以添加类似苹果系统上的消息未读数吗?
A:原生系统不可以,定制后的部分可以,比如小米,三星等。

Q:在没有美工帮助的情况下怎么才能有精致的图标
A:谷歌官方图标库,网页形式的,你值得拥有,而且可以实现一张图多种颜色,利用tint属性,设置不同的color就是不同的颜色图片,极其简单方便。然而这个网址也有可能打不开,比如最近我就打不开了,之前还能打开的,之前也没有翻墙,莫名其妙啊,不过还可以参考google的github图标库。

Q:选择图库图片,即使本地新增了图片,然而还是无法看到,图库未更新,怎么办
A:在选择图片类里添加发送广播,如下代码:。可参考这里

Q:有没有根据歌曲名获取歌词的api
A:目前没有,只有根据歌曲id获取的,然而却不知道怎么获取歌曲id,因为api还没开放,只能自己通过抓包截取软件获取。参考http://music.163.com/api/song/media?id=93921
http://music.163.com/api/song/lyric?os=pc&id=93921&lv=-1&kv=-1&tv=-1
http://www.111cn.net/sj/android/94611.htm

Q:list集合的全体赋值问题,可以直接使用等于号吗
A:绝对不可以,必须使用addAll方法

Q:for循环thread线程多个同步执行
A:使用synchronized(this),参考如下代码:

new Thread(new Runnable() {                                            @Override                                            public void run() {                                                synchronized(this){                                                 for (int i = 0; i < listData.size(); i++) {                                                 // 耗时方法try {                                                        Thread.sleep(100);                                                    } catch (InterruptedException e) {                                                        e.printStackTrace();                                                    }                                                 }  }}                                        }).start();

Q:在使用tabActivity等类似的父容器类时,要注意在子容器中显示加载中对话框的时候传的context参数吗?
A:不能使用子容器的context,应该使用getParent()作为dialog的context参数

Q:打包过程中出现如下错误: UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded
A:在build.gradle的android标签下添加如下代码:参考stackoverflow链接

    dexOptions {        javaMaxHeapSize "4g"    }

Q:TextView的跑马灯效果
A:文本要超过textview的宽度,宽度可以是固定的或者match_parent加margin,然后xml中设置

                    android:ellipsize="marquee"                    android:marqueeRepeatLimit="marquee_forever"                    android:singleLine="true"

在java代码中添加

                    textView.setSelected(true);

Q:方法数过多的错误,如下

Error:The number of method references in a .dex file cannot exceed 64K.Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.htmlError:Execution failed for task ':app:transformClassesWithDexFor_360Debug'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

A:添加multiDex支持

   compile 'com.android.support:multidex:1.0.1'   defaultConfig {   multiDexEnabled true}   android:name="android.support.multidex.MultiDexApplication"

如果集成自Application的BaseApplication

 @Override     protected void attachBaseContext(Context base) {         super.attachBaseContext(base);         MultiDex.install(this) ;     }

Q:Error:Error: Expected resource of type styleable [ResourceType]
A:对应方法处加上@SuppressWarnings(“ResourceType”)

Q:手机无法被手机助手检测到,打开设备管理器设备提示:Windows 无法验证此设备所需的驱动程序的数字签名。某软件或硬件最近有所更改,可能安装了签名错误或损毁的文件,或者安装的文件可能是来路不明的恶意软件。 (代码 52)
A:win10下禁用驱动签名http://jingyan.baidu.com/article/29697b910f8f59ab20de3c9e.html

Q:

 Gradle sync failed: Could not run build action using Gradle installation 'E:\Program Files\Android\Android Studio\gradle\gradle-2.14.1'.         Consult IDE log for more details (Help | Show Log)

A:

禁用offline work后,再启用试试,反正我 这样做就可以了

0 0