《第一行代码Android》阅读笔记

Android知识点记录

git 使用

git push origin master

origin 指的是远程版本库的 git 地址
master 指的是同步到哪个分支,这儿是 master 分支

本地貌似有个缓存为 origin/master 分支

因为我在 github 在线修改了 README.md 文件,github 网站上的是修改了。但是本地执行git status命令,得到下面的提示

TomChens-MacBook-Pro:android tomchen$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

说本地的分支是和origin/master同步的。

这时候需要用

git pull origin master

实现从远程获取最新代码,合并到本地。

Animation 构造器

public RotateAnimation (float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

参数说明

fromDegrees:旋转的开始角度。

toDegrees:旋转的结束角度。

pivotXType:X轴的伸缩模式,可以取值为ABSOLUTE(绝对值)、RELATIVE_TO_SELF(相对自身)、RELATIVE_TO_PARENT(相对父空间)。

pivotXValue:X坐标的伸缩值。

pivotYType:Y轴的伸缩模式,可以取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。

pivotYValue:Y坐标的伸缩值。

注意:旋转表示一个控件绕着一个点做旋转(平面旋转)。这个旋转是围绕一个点,而这个点是由百分比决定的,比如相对于自身时x为0.5,y为0.5,那么这个点就是该控件的中心;如果x为1,y为1,那么这个点就是控件的右下角;相对父控件时x为0.5,y为0.5,那么这个点就是该父控件的中心。

围绕控件中心旋转的方法:(旋转的控件布局要是一个正方形,即比较严格对称的)

RotateAnimation  rotateAnimation = new RotateAnimation(0, 180,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);

Android:visibility

Note
Android控件有visibility属性,可以在xml文件中用android:visibility指定,或者用public void setVisibility (int visibility)方法指定

其属性有3个分别为“visible”、“invisible”、“gone”。
visible表示可见,invisible和gone都不可见

但是gone不占用原来的位置和大小,invisible还占有原有空间


AlertDialog

Note*
AlertDialog类中有一个setCancelable(boolean)方法,表示是否可以用手机上的back键取消对话框。


摘自google官方api
java.lang.Object
↳ android.app.Dialog
↳ android.app.AlertDialog
public void setCancelable (boolean flag)
Added in API level 1
Sets whether this dialog is cancelable with the BACK key.


LayoutInflater.from(context).inflate(R.layout.title, null)

在自定义UI中,经常使用 LayoutInflater.from(context).inflate(R.layout.title, null)
或 LayoutInflater.from(getContext()).inflate(R.layout.title, this)

关于第2个参数是null 还是非null的问题,查看了API。

API
java.lang.Object
↳ android.view.LayoutInflater
public View inflate (int resource, ViewGroup root)

Added in API level 1
Inflate a new view hierarchy from the specified xml resource. Throws InflateException if there is an error.

Parameters
resource ID for an XML layout resource to load (e.g., R.layout.main_page)
root Optional view to be the parent of the generated hierarchy.
Returns
The root View of the inflated hierarchy. If root was supplied, this is the root View; otherwise it is the root of the inflated XML file.
如果第2个参数非空,返回值为第2个参数;个人认为返回值为第1个参数(此处有疑惑)
inflate(R.layout.res, parent, true) 等价于 inflate(R.layout.res, parent)
inflate(R.layout.res, parent, false) 不等价于nflate(R.layout.res, null)


ListView 优化性能

在继承ArrayAdapter,可能要重载public View getView (int position, View convertView, ViewGroup parent)方法
可以判断View convertView 是否为空,以此觉得重新加载还是不加载,优化性能。

API
java.lang.Object
↳ android.widget.BaseAdapter

↳ android.widget.ArrayAdapter
public View getDropDownView (int position, View convertView, ViewGroup parent)

Added in API level 1
Get a View that displays in the drop down popup the data at the specified position in the data set.

Parameters
position index of the item whose view we want.
convertView the old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view.
parent the parent that this view will eventually be attached to
Returns
a View corresponding to the data at the specified position.
public View getView (int position, View convertView, ViewGroup parent)

Added in API level 1

开发项目小技巧

Tips
Ecplise中暂时不用的项目,右键项目“Close Project”,减少程序卡顿情况。

Ecplise输入“syso”,再按 Alt+/ 可以快速加入System.out.println();

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值