欢迎Follow我的GitHub, 关注我的CSDN.

我会介绍关于Android的一些有趣的小知识点. 本文是第三篇, 其余第一篇, 第二篇.

imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Android" title="">


1. UIAutomatorViewer

自己主动化測试是Android測试的趋势, 稳定\复用, 最经常使用的工具就是Espresso.

使用UIAutomatorViewer获取资源的Id,

位置/android-sdk/tools/uiautomatorviewer, 点击就可以使用.


2. GitHub标签

网址, 比方:




3. 有趣的改动SVG库

地址, 载入SVG格式的图片, 改动颜色属性.


4. 请求和生成的Json插件

JSONOnlineViewer, 网络请求插件, 获取Json数据, 位置View->JSONViewer.

GsonFormat, 依据Json自己主动生成类的插件, 在Command+N里面.

附一张插件的截图, 其它任意.


5. Retrofit2+Okhttp3的Interceptor设置方式

Retrofit升级到beta3版本号, 使用了最新Okhttp3, Interceptor的设置方式发生改变.

旧版

OkHttpClient client = new OkHttpClient().Builder();

HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
MarvelSigningInterceptor signingInterceptor = new MarvelSigningInterceptor(
BuildConfig.MARVEL_PUBLIC_KEY, BuildConfig.MARVEL_PRIVATE_KEY); client.interceptors().add(signingInterceptor);
client.interceptors().add(loggingInterceptor);

替换, 新版

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); MarvelSigningInterceptor signingInterceptor = new MarvelSigningInterceptor(
BuildConfig.MARVEL_PUBLIC_KEY, BuildConfig.MARVEL_PRIVATE_KEY); OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(signingInterceptor)
.addInterceptor(loggingInterceptor)
.build();

否则可能会发生: HTTP 409 Conflict, 未输入正确的验证方式, 私钥错误.


6. okhttp-logging-interceptor输出log信息

參考, 能够输出log信息, 使用, 当前版本号是3.0.1.

compile "com.squareup.okhttp3:logging-interceptor:${libs.okhttp}"

输出參考:

D/OkHttp: <-- 200 OK http://gateway.marvel.com/v1/public/characters?

offset=0&... (1552ms, unknown-length body)

7. 透明statusbar和全屏ImageView

status bar设置成为透明颜色.

    <style name="AppTheme.NoStatusBar">
<item name="android:windowTranslucentStatus">true</item>
</style>

页面的根布局是CollapsingToolbarLayout.

<android.support.design.widget.CollapsingToolbarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/christmas"/> </android.support.design.widget.CollapsingToolbarLayout>

效果


8. Android Studio模板

位置: File->Other Settings->Default Settings->Editor->Live Templates

熟练之后, 依据简写+Tab就能够使用了, 当然也能够自己加入.

自己定义模板:

缩写(Abbreviation), 描写叙述(Description), 内容(Template text), 应用场景, 格式化.


9. 推荐动画效果的站点

网址, 站点里面有非常多好玩的动画效果, 并且都是编程实现, 方便移植, 如雪花效果.


10. ListView的ViewHolder

Android官方推荐使用RecyclerView取代ListView, 可是非常多守旧的人不想这么做, 那么, 也须要使用ViewHolder提升载入速度. 參考.

基本使用方法.

static class ViewHolder() {
TextView testName;
TextView testDesc;
} ... @Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView; // 初始化ViewHolder
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) parent.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.view_test_row, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.testName = (TextView) rowView.findViewById(R.id.test_tv_name);
viewHolder.testDesc = (TextView) rowView.findViewById(R.id.test_tv_desc);
rowView.setTag(viewHolder);
} // 使用ViewHolder
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.testName.setText("Test: " + position);
holder.testDesc.setText("This is number " + position + ". "); return rowView;
}

OK, that’s all! Enjoy it.

最新文章

  1. showPrompt弹框提示
  2. 完整的社交app源码android+laravel
  3. QPS/QPS/PV/UV/服务器数量/并发数/吐吞量/响应时间计算公式
  4. SQL迁移到ORACLE实例
  5. 函数改变全局变量-JS
  6. Codeforces Round #143 (Div. 2)
  7. 一、C# 概述
  8. 我的SD卡乱码解决方案
  9. OpenCV视屏跟踪
  10. poj2909 || poj2262
  11. bettercap实现内网Dns欺骗
  12. python学习之字符串(上)
  13. http get(swift and oc)
  14. c++---天梯赛---N个数求和
  15. redis在java客户端的操作
  16. 如何发起、防御和测试XSS攻击,我们用DVWA来学习(上)
  17. 解决 jQuery validation插件 valid()方法总是返回true的问题
  18. 洛谷P3957 跳房子
  19. 非定制UIImagePickerController的使用
  20. Android :Activity、Adapter、List的初步学习

热门文章

  1. 浏览器在一次 HTTP 请求中,需要传输一个 4097 字节的文本数据给服务端,可以采用那些方式?
  2. 大数据学习——sql练习
  3. 第四章 vim 可视模式
  4. TOJ 2353: Billiard
  5. 九度oj 题目1022:游船出租
  6. redis介绍和安装和主从介绍(二)
  7. linux的自启动服务脚本的(/etc/rc.d/init.d或者其链接/etc/init.d)
  8. 【Luogu】P2051中国象棋(DP)
  9. Bzoj1083 1083: [SCOI2005]繁忙的都市【MST】
  10. java 数据库连接的几个步骤