欢迎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.

Android开发Tips(3)的更多相关文章

  1. Android开发Tips(2)

    欢迎Follow我的GitHub, 关注我的CSDN. 我会介绍关于Android的一些有趣的小知识点. 上一篇. 1. Dagger2的开发顺序 Module -> Component -&g ...

  2. Android开发Tips(5)

    欢迎Follow我的GitHub, 关注我的CSDN. 介绍关于Android的一些有趣的小知识点. 本文是第五篇了, 差点儿一周一篇, 欢迎阅读. 其余第一篇, 第二篇, 第三篇, 第四篇. 1. ...

  3. [Android开发Tips]Bean的定义

    Bean: public class Data extends BaseBean { public ArrayList<DataItem> data = new ArrayList< ...

  4. Android开发环境的演变

    之前安装过eclipse,给我的感觉是,好生麻烦.刚开始自己装花了好多时间.隐约还记得有两个小tips: 1)打开时出现 “failed to load the JNI shared library ...

  5. Android开发学习---使用Intelij idea 13.1 进行android 开发

    1.为什么放弃eclipse?太卡!! 实在受不了eclipse的卡了,运行WEB项目还好,但android开发实在太慢,太慢!经常卡死,CPU经常被占满! 看网上很多人都说比Intelij idea ...

  6. 推荐一些顶级的Android开发书籍(转)

    本帖对Android开发菜鸟和中级老兵同样适用,因为本帖重点列出了那些最常用的Android开发资源. 推荐书籍 你或许觉得,都现在了,再去看个什么书来学习Android开发,这方法应该早就过时了.没 ...

  7. Android开发环境--eclipse和Android Studio

    一.eclipse下载.安装.配置 因为eclipse是之前就下载过的,现在只能大概说一下eclipse的下载安装过程. 1.下载jdk,配置java环境变量  (1)在官网(http://www.o ...

  8. [Xamarin.Android] ActionBar Tips

    [Xamarin.Android] ActionBar Tips ActionBar用途 快速搞懂 ActionBar的用途,可以参考下列文章: [Android]使用 ActionBarCompat ...

  9. [Xamarin.Android] Fragment Tips

    [Xamarin.Android] Fragment Tips Fragment用途 快速搞懂 Fragment的用途,可以参考下列文章: Android Fragment 使用心得 Android ...

随机推荐

  1. PAT Basic 1010

    1010 一元多项式求导 设计函数求一元多项式的导数.(注:x^n^(n为整数)的一阶导数为n*x^n-1^.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数). ...

  2. ZOJ 3469 区间DP Food Delivery

    题解 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm ...

  3. linux相关技术

    1.查询服务器tcp连接状态及连接数 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

  4. vuex相关知识点

    vuex简单理解转载博客 vuex从入门到入门------state:从 store 实例中读取状态最简单的方法就是在计算属性中返回某个状态------Getters:可以很容易地在任何组件中使用它- ...

  5. I/O输入系统

    I/O输入系统 计算机有两个主要任务:I/O操作与计算处理.在许多情况下,主要任务是I/O操作.而计算处理只是附带的. 操作系统在计算机I/O方面的作用是管理和控制I/O操作和I/O设备. 概述 对与 ...

  6. 九度oj 题目1160:放苹果

    题目描述: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. 输入: 第一行是测试数据的数目t(0 <= t ...

  7. [BZOJ2733] [HNOI2012]永无乡(并查集 + 线段树合并)

    传送门 一看到第k大就肯定要想到什么权值线段树,主席树,平衡树之类的 然后就简单了 用并查集判断连通,每个节点建立一颗权值线段树,连通的时候直接合并即可 查询时再二分递归地查找 时间复杂度好像不是很稳 ...

  8. 常州模拟赛d2t2 小X的密室

    题目描述 密室中有 N 个房间,初始时,小 X 在 1 号房间,而出口在 N 号房间. 密室的每一个房间中可能有着一些钥匙和一些传送门,一个传送门会 单向地 创造一条从房间 X 到房间 Y 的通道.另 ...

  9. cf711E ZS and The Birthday Paradox

    ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...

  10. 洛谷P2625 豪华游轮

    题目描述 有一条豪华游轮(其实就是条小木船),这种船可以执行4种指令: right X : 其中X是一个1到719的整数,这个命令使得船顺时针转动X度. left X : 其中X是一个1到719的整数 ...