编程经验分享

笑看嫣红染半山,
逐风万里白云间,
逍遥此身不为客,
天地三才任平凡。

0%

原文链接:https://www.bignerdranch.com/blog/understanding-androids-layoutinflater-inflate/

由于我们很容易习惯公式化的预置代码,有时我们会忽略很优雅的细节。LayoutInflater以及它在Fragment的onCreateView()中填充View的方式带给我的就是这样的感受。这个类用于将XML文件转换成相对应的ViewGroup和控件Widget。我尝试在Google官方文档与网络上其他讨论中寻找有关的说明,而后发现许多人不但不清楚LayoutInflater的inflate()方法的细节,而且甚至在误用它。

阅读全文 »

转自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0116/3874.html

0、写在前面

本文涉及到屏幕密度的讨论,这里先要搞清楚 DisplayMetrics 的两个变量,摘录官方文档的解释:

  • density:The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5”x2” screen), providing the baseline of the system’s display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.
    This value does not exactly follow the real screen size (as given by xdpi and ydpi, but rather is used to scale the size of the overall UI in steps based on gross changes in the display dpi. For example, a 240x320 screen will have a density of 1 even if its width is 1.8”, 1.3”, etc. However, if the screen resolution is increased to 320x480 but the screen size remained 1.5”x2” then the density would be increased (probably to 1.5).
  • densityDpi:The screen density expressed as dots-per-inch.

简单来说,可以理解为 density 的数值是 1dp=density px;densityDpi 是屏幕每英寸对应多少个点(不是像素点),在 DisplayMetrics 当中,这两个的关系是线性的:

阅读全文 »

###vi中为每行文本开头插入行号:

1
2
3
4
5
6
7
:g/^/exe ":s/^/".line(".")

:%!cat -n 字数最少的方法
:%s/^/\=line(".").",\t"/ 最正规的方法
:let i=0|g/^/s//\=i.','/ |let i+=1 不用函数的方法
:g/^/exec "s/^/".strpart(line(".")." ", 0, 4)
:g/^/exec "s/^/".line(".")."\t"</pre>

前言

接触了这么久的Android,发现有些术语的理解还是模模糊糊,所以今天就来理清一下这些概念。

apk扩展名

apk是Android包的扩展名,一个Android包包含了与某个Android应用程序相关的所有文件,apk文件将AndroidManifest.xml文件、应用程序代码(dex文件)、资源文件和其他文件组成一个压缩包,一个项目只能打包压缩成一个apk文件。

阅读全文 »

// 禁止CentOS7自带的firewalld,安装并启用iptables
$ systemctl disable firewalld
$ yum install iptables-services
$ systemctl enable iptables
$ cp /usr/libexec/iptables/iptables.init /etc/init.d/iptables
$ /etc/init.d/iptables save
// 在Linux中,可以很简单地用netfilter/iptables框架禁止IP地址:
$ sudo iptables -A INPUT -s 1.1.1.1 -p TCP -j DROP
// 如果你想要完全屏蔽一个IP地址段,你可以用下面的命令很简单地做到:
阅读全文 »

在移动应用开发和运营的过程中,版本管理是一个老生常谈的基础问题,一些版本的基本概念也常常会困扰我们的研发和运营人员。同时,手动管理软件版本,也常常会因为不小心导致后续的发布和更新问题。

这里,我准备了一些 iOS 和 Android 版本的基础知识,以及如何在应用中获取版本信息和如何使用 Xcode 和 Android Studio 自动管理版本号。

阅读全文 »

阅读全文 »

复杂的软件必须有清晰合理的架构,否则无法开发和维护。
MVCModel-View-Controller)是最常见的软件架构之一,业界有着广泛应用。它本身很容易理解,但是要讲清楚,它与衍生的 MVPMVVM 架构的区别就不容易了。
昨天晚上,我读了《Scaling Isomorphic Javascript Code》,突然意识到,它们的区别非常简单。我用几段话,就可以说清。

阅读全文 »

有时候我们在github上看到一些比较好的项目,我们都会fork一下它,然后在本地进行操作,但是fork之后,项目是不会跟源项目保持同步的,需要我们自己进行一些操作让其同步。

我们以最近Nutz成员正在开发的QA系统为例,假如我们clone自己fork过来的项目的保存路径为:~/ngqa_gevinhjy

阅读全文 »