曲阳网站制作公司,阿里云 wordpress邮件,什么是网络营销?网络营销有哪些内容?,中国比较大的外包公司本文讲的是Android Coding利器之掌握小技巧#xff0c;助你Coding更上一层楼~#xff0c;话说前几天在网上浏览到一大牛写的关于Android布局优化的文章#xff0c;看后感触很深#xff0c;回过头看看自己写过的代码#xff0c;发现还是有不少需要改进#xff0c;今天找不… 本文讲的是Android Coding利器之掌握小技巧助你Coding更上一层楼~话说前几天在网上浏览到一大牛写的关于Android布局优化的文章看后感触很深回过头看看自己写过的代码发现还是有不少需要改进今天找不到那天看的文章了只能自己总结一些以后有机会再次补充吧~ 。 本文目标 通过举例说明Android开发中的小技巧让你我更6的玩转Android~ 掌握小技巧助你Coding更上一层楼~ 本文将通过以下几点进行举例说明 Android Studio 常用快捷键;Android Studio 强大的代码补全;Android Studio 插件;Android 布局优化Android Studio 常用快捷键 只从接触Android Studio之后愈发离不开这个开发神器了~也是越接触越能感觉Studio的魅力今天为大家带来LZ开发中常用的一些快捷键。 1. ShiftF6 全局修改 LZ一般使用这种方式去改全局变量或者资源名称。 2. AltF7 查看全局引用 LZ一般优化时会使用这个去查看某个方法或者变量全局引用 3. CtrlShift上下键 移动代码 4. 强大的 AltInsert AltInsert这个快捷键异常强大里面包含生成getsettoString ... 等一系列爱不释手~ 5. CtrlF 局部查找 用这个找个方法啥的很6但是仅限于局部也就是本类 6. CtrlAltV 自动初始化变量 引入变量类型 只适用于基本类型 7. CtrlD 向下复制 还在CtrlCCtrlV嘛?Out了骚年~ 8. CtrlAltL 格式化代码 这个不得不说都成为一种习惯写好一部分总是习惯格式化下代码 9. CtrlAltO 去除无效引用(包名) 去除无用引用包以及格式化代码都成为LZ标配了~GGG 10. CtrlJ 强大的代码补全 不得不说这个真的666啊~ 11. CtrlAltT 快速生成类似try块 if块 while等 这个LZ一般还是用于生成try块方便在项目中针对某些会出现异常的代码块都需要添加try 块防止异常导致崩溃 12. 贯穿全局的AltEnter 此子可用于导包或者修正某些异常类似于某些方法需要抛出异常或者添加try块等 13. CtrlN 查找类 不想用鼠标还想找个类肿么办?CtrlN来帮你~ 14. CtrlE 查看浏览历史 15 .AltShiftC 对比本地历史纪录 这个技能不错666 16. CtrlShiftSpace 自动补全代码 17. CtrlY 删除当前行 18. F2 或ShiftF2 高亮错误或警告快速定位 19. AltJ 多行编辑 想要一次性写多行么?想一次性修改多行么?完全不是梦~ 关于常用快捷键介绍到此以后用到再补充~ Android Studio 强大的代码补全 在上面已经为大家列举LZ个人开发中常用的一些快捷键下面简单说明下强大的代码补全功能~继续感受Android Studio的魅力~ 骚年还在手动写public static final吗? 作为项目中常用也几乎为必备的东西强大的Studio早已看穿一切~当然LZ这里没有全面大家可以自行挖掘~或者直接使用快捷键~ Android Studio 插件 强大的Android Studio背后肯定会有n多插件使其更加优秀下面将列举LZ常用的几种具体大家可自行发掘~ 1. GsonFormat json快速生成实体类 还在为Json编写实体类犯愁吗?赶快来使用它~ 2. ButterKnife Zelezny 一键生成注解 简化代码 使用这个需要添加相应的依赖为了省事儿LZ直接盗图了~勿怪 3. Parcelable 序列化 Android中的序列化有两种方式分别是实现Serializable接口和Parcelable接口但在Android中是推荐使用Parcelable而且这边过程比较繁琐幸好有这神器~ 4. Genymotion 优秀的模拟器 不解释也不截图了不过现在谷歌推出的模拟器使用起来也还不错个人比较支持谷歌更新后的模拟器 LZ目前尝试用的也就以上几个当然还有很多优秀的插件附上地址大家自行浏览选择使用即可~ https://www.zhihu.com/question/28026027 Android 布局优化 布局优化这是个有意思的话题下面通过不同例子一起来看看吧~ 一、巧用android:drawab系列Style提高代码可读性以及简洁性 TextView这个东西想必大家用的都熟透了吧?今天我们来说说如何更好玩转TextView。 举一个很通用的例子微信我的界面布局 大家注意到钱包收藏相册等布局了么? 以前我们会这么写 LinearLayout android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop15dp android:background#FFF android:orientationhorizontal android:padding15dp ImageView android:layout_width30dp android:layout_height30dp android:backgroundmipmap/ic_launcher_1/ TextView android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_gravitycenter_vertical android:text钱包/ /LinearLayout LinearLayout android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop15dp android:background#FFF android:orientationhorizontal android:padding15dp ImageView android:layout_width30dp android:layout_height30dp android:backgroundmipmap/ic_launcher_1/ TextView android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_gravitycenter_vertical android:text钱包/ /LinearLayout ... ... 如果点击项多的话反而显得乱而且多了很多无用的代码今天我们来尝试新的玩法~ TextView android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop15dp android:background#FFF android:drawableLeftmipmap/ic_launcher_1 android:drawablePadding10dp android:gravitycenter_vertical android:padding10dp android:text钱包/ TextView android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop15dp android:background#FFF android:drawableLeftmipmap/ic_launcher_1 android:drawablePadding10dp android:gravitycenter_vertical android:padding10dp android:text钱包/ ... ... 俩者实现效果如下 TextView多的话还可以提取Style文件代码简洁易读。 二、TextView跑马灯 附上效果图 部分代码如下 TextView android:idid/id_test android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop15dp android:background#FFF android:singleLinetrue android:ellipsizemarquee android:marqueeRepeatLimitmarquee_forever android:text失恋算个啥轻轻的你走吧千万别后悔因为只要你一挥手就会发现已经有那等不及的意中人正偷偷摸摸拉你的手/ 记得Activity要设置一个属性否则无效。 findViewById(R.id.id_test).setSelected(true); 要想实现跑马灯效果必须满足一个条件就是TextView内容必须超出屏幕否则无效!当然你可以自定义。 三、关于显示价格优化 效果如下 按照之前的想法我们会这么玩 TextView android:layout_widthwrap_content android:layout_heightwrap_content android:text您需要支付/TextView android:layout_widthwrap_content android:layout_heightwrap_content android:text50 android:textColorandroid:color/holo_red_light/ 可有简单用法干嘛还多写一个TextView这不是浪费嘛?瞧着~ string文件中这样写 string namestring_pay_price您需要支付%1$s/string !-- %1$s代码第一位是String类型同理第二位%2$s -- Activity定义方法 private void setPayPrice(String payPrice) { tvShow.setText(getString(R.string.string_pay_price, payPrice)); SpannableStringBuilder builder new SpannableStringBuilder(tvShow.getText().toString()); ForegroundColorSpan colorSpan new ForegroundColorSpan(Color.RED); // 根据要求自定义颜色值 builder.setSpan(colorSpan, 4, tvShow.getText().toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tvShow.setText(builder); } 四、自动链接TextView内容例如网址电话e-mail等 效果如下 代码部分 TextView android:idid/id_test android:layout_widthwrap_content android:autoLinkall android:text贺贺博文地址http://blog.csdn.net/u012400885 \n查询电话13811604922 android:layout_heightwrap_content/ 五、巧用LinearLayout节省不必要代码~ 下面为大家附上一个简单效果图大家首先想想如果是你怎么写? 这里为大家引入另一种写法也就是小标题如何巧用LinearLayout 首先编写shape文件很简单设置高度和颜色。 shape xmlns:androidhttp://schemas.android.com/apk/res/android size android:height15dp/ solid android:color#FFF000//shape 其次在布局文件中设置divider以及showDividers属性即可。 ?xml version1.0 encodingutf-8?LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android xmlns:toolshttp://schemas.android.com/tools android:layout_widthmatch_parent android:layout_heightmatch_parent android:background#FFF android:dividerdrawable/shape_0 android:orientationvertical android:showDividersmiddle|beginning|end tools:contextcn.hlq.hlqstudyandroid.MainActivity TextView android:layout_widthmatch_parent android:layout_heightwrap_content android:drawableLeftmipmap/ic_launcher_1 android:drawablePadding10dp android:gravitycenter_vertical android:padding10dp android:textitem项111/ TextView android:layout_widthmatch_parent android:layout_heightwrap_content android:drawableLeftmipmap/ic_launcher_1 android:drawablePadding10dp android:gravitycenter_vertical android:padding10dp android:textitem项222//LinearLayout 下面简单介绍下android:showDividers属性 android:showDividersmiddle|beginning|end鉴名其意三个属性值分别为 中间 开始部分 结束部分也就是在三个部分显示分割线。 有个哥儿们会说了不是还有v7包下LinearLayoutCompat不也能实现分割线吗? 确实不过我试了下感觉俩者一样这里就不做过分说明了~ 六、禁止截屏功能间接保护App 想想实现禁止应用截屏只需要一行代码如下 getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); 防止setContentView后即可之后截屏的时候会提示以下内容 结束语 东西很简单LZ简单总结了下给自己留点东西~ 本文作者佚名 来源51CTO 原文标题Android Coding利器之掌握小技巧助你Coding更上一层楼~