首页 > 移动平台 > 详细

Android第三天

时间:2017-01-16 22:37:59      阅读:325      评论:0      收藏:0      [点我收藏+]

1.UI设计:

常用组件

TextView     显示文字

EditText      输入文字编辑框        maxLines="2"   最大行2行

Button        按钮   有点击事件  监听点击事件

ImageView   图片    src="@drawable/ic_launcher"

ProgressDialog    final ProgressDialog pd = ProgressDialog.show(AtyMessage.this,getResources().getString(R.string.connecting),getResources().getString(R.string.connecting_to_server));

 AlertDialog  弹出对话框,一般是“确定”“取消”

2.四种基本布局

LinearLayout     线性布局       android:orientation=“horizontal”  水平      vertical  垂直

RelativeLayout  相对布局        

FrameLayout          都放在左上角

TableLayout     表格布局

系统布局不够用,那就自定义布局。

<include layout="@layout/title" />      其中title位于layout下面的的title.xml

3.最常用和最难用的布局控件--ListView

当程序中有很多数据需要显示的时候,需要用ListView。ListView可以上下滑动将屏幕外面的数据滚到屏幕内。

借助适配器可以数组中的数据传递给ListView,最好用的是ArrayAdapter,支持很多泛型。

adapter = new AtyMessageCommentListAdapter(this);
setListAdapter(adapter);

适配器有三个参数。
public View getView(int arg0, View convertView, ViewGroup arg2) {
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.aty_timeline_list_cell,null);
convertView.setTag(new ListCell((TextView) convertView.findViewById(R.id.tvCellLable)));
}
ListCell lc = (ListCell) convertView.getTag();
Comment comment = getItem(arg0);
lc.getTvCellLable().setText(comment.getContent());
return convertView;
}


ListView的优化:ViewHolder提升运行效率
如果convertView为空,则用LayoutFlater去加载布局;
如果convertView不为空,直接对convertView进行重用。

ListView的点击事件
listView.setOnItemClickListener(){...}

4.单位+尺寸
px pt受限
dp sp帮忙
android/sdk/tools/draw9patch.bat文件,制作Nine-Patch图片,解决图片拉伸后显示的问题。
  

Android第三天

原文:http://www.cnblogs.com/pangshuangle/p/6291072.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!