您的位置:首页 > 移动开发 > Android开发

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

2015-08-11 21:22 471 查看

Android知识点记录

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: