《第一行代码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
开发项目小技巧
TipsEcplise中暂时不用的项目,右键项目“Close Project”,减少程序卡顿情况。
Ecplise输入“syso”,再按 Alt+/ 可以快速加入System.out.println();
相关文章推荐
- Android手机进行无线EAP-TLS证书认证配置
- android常用到得单元测试
- Android自定义属性时TypedArray的使用方法
- 教你自己实现一个事件总线EventBus
- MPAndroidChart开源图表库---折线图
- Android studio主题风格的添加
- ImageLoader框架使用步骤
- Android屏幕适配
- Android项目中如何用好构建神器Gradle?
- Android单元测试异常总结---Test run failed:Unable to find instrumentation target package
- Android多个按钮下本Activity按钮事件处理
- Android_Activity传值和跳转
- Android下获取各种存储目录
- Android-SD卡文件夹创建和删除实现
- 个人对Android Touch事件机制的理解
- Android多线程问题—— AsyncTask机制
- 修改Android studio 中svn版本
- Android边缓冲边播放视频(ijkplayer的编译和使用)
- android ButterKnife
- android adb 权限修改