今天开始接触和熟悉Android上层应用,学海无涯,回头是岸 -_-||

三种常见布局方法:Linearlayout(线性布局)、TableLayout?(表格布局)、Relative Layout(相对布局)。

相对布局比起前面两种布局方法而言更随意,用户可以将控件放在自己所希望的任何位置。

在LinearLayout和TableLayout中常见的指令有

android:id——控件指定相应ID
android:text——控件中显示文字。注意尽量使用Strings.xml
android:gravity——控件中文字基本位置,如center、left、right、center_horizontal等。
android:textsize——控件中字体大小,单位为pt。
android:background——控件背景色
android:width——控件宽度
android:height——控件高度
android:padding——空间内边距,指控件当中内容到空间的距离。其中有android:padding_left、android:padding_right等。
android:siglelise——如果设置为真,控件内容将在同一行显示。
android:margin——外边距。

相对布局Relative Layout

android:Layout_above——将控件底部至于给定控件之上
android:Layout_below——将控件顶部至于给定控件之下
android:Layout_toleftof——将控件左边缘至于给定控件右边
android:Layout_toRightof——将控件左边缘至于给定控件右边
android:Layout_alignBaseline——将控件的Baseline与指定控件的Baseline对齐。
android:Layout_alignleft——将控件的左边与指定控件的左边对齐。
android:Layout_alignright——将控件的右边与指定控件右边对齐。
android:Layout_alignTop——将控件的顶部与指定控件顶部对齐。

android:Layout_alignParentBottom——为真,控件与父控件对齐。
android:Layout_centerHorizontal——为真,空间被至于水平方向中央。
android:Layout_centerinParent——为真,至于父控件水平/垂直方向中央。
android:Layout_centervertural——被置于垂直方向中央。

intent-filter
1 android.intent.action.MAIN决定应用程序最先启动的Activity。
2 android.intent.category.LAUNCHER决定应用程序是否显示在程序列表里。

intent调用应用程序
例子: 调用Google浏览器
Uri uri = Uri.parse("http://www.android123.com.cn");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

常用的应用程序调用

显示web网页:

1. Uri uri = Uri.parse("http://www.android123.com.cn");
2. Intent it = new Intent(Intent.ACTION_VIEW,uri);
3. startActivity(it);

显示google地图:

1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.Action_VIEW,uri);
3. startActivity(it);

Maps路径规划:

1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW,URI);
3. startActivity(it);

拨打电话:
1. Uri uri = Uri.parse("tel:xxxxxx");
2. Intent it = new Intent(Intent.ACTION_DIAL, uri);
3. startActivity(it);

1. Uri uri = Uri.parse("tel.xxxxxx");
2. Intent it =new Intent(Intent.ACTION_CALL,uri);

注意需要权限 <uses-permission id="Android.permission.CALL_PHONE" />

发送SMS/MMS

1. Intent it = new Intent(Intent.ACTION_VIEW);
2. it.putExtra("sms_body", "android开发网欢迎您");
3. it.setType("vnd.android-dir/mms-sms");
4. startActivity(it);

发送短信

1. Uri uri = Uri.parse("smsto:10086");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. it.putExtra("sms_body", "10086"); //正文为10086
4. startActivity(it);

发送彩信

1. Uri uri = Uri.parse("content://media/external/images/media/10"); //该Uri根据实际情况修改,external代表外部存储即sdcard
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra("sms_body", "android123.com.cn");
4. it.putExtra(Intent.EXTRA_STREAM, uri);
5. it.setType("image/png");
6. startActivity(it);
发送Email

2. Uri uri = Uri.parse("mailto:android123@163.com");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. startActivity(it);

1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_EMAIL, "android123@163.com");
3. it.putExtra(Intent.EXTRA_TEXT, "android开发网测试");
4. it.setType("text/plain");
5. startActivity(Intent.createChooser(it, "选择一个Email客户端"));

1. Intent it=new Intent(Intent.ACTION_SEND);
2. String[] tos={"android123@163.com"}; //发送到
3. String[] ccs={"ophone123@163.com"}; //抄送
4. it.putExtra(Intent.EXTRA_EMAIL, tos);
5. it.putExtra(Intent.EXTRA_CC, ccs);
6. it.putExtra(Intent.EXTRA_TEXT, "正文");
7. it.putExtra(Intent.EXTRA_SUBJECT, "标题");
8. it.setType("message/rfc822"); //编码类型
9. startActivity(Intent.createChooser(it, "选择一个Email客户端"));

Email添加附件

1. Intent it = new Intent(Intent.ACTION_SEND);
2. it.putExtra(Intent.EXTRA_SUBJECT, "正文");
3. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/nobody.mp3"); //附件为sd卡上的nobody MP3文件
4. sendIntent.setType("audio/mp3");
5. startActivity(Intent.createChooser(it, "选择一个Email客户端"));

播放多媒体

1.
2. Intent it = new Intent(Intent.ACTION_VIEW);
3. Uri uri = Uri.parse("file:///sdcard/nobody.mp3");
4. it.setDataAndType(uri, "audio/mp3");
5. startActivity(it);

1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); //从系统内部的MediaProvider索引中调用播放
2. Intent it = new Intent(Intent.ACTION_VIEW, uri);
3. startActivity(it);

Uninstall卸载程序

1. Uri uri = Uri.fromParts("package", packageName, null); //packageName为包名,比如com.android123.apkInstaller
2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
3. startActivity(it);

进入联系人界面

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
startActivity(intent);

查看某个联系人,当然这里是ACTION_VIEW,如果为选择并返回action改为ACTION_PICK,当然处理intent时返回需要用到startActivityforResult

Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, ID);//最后的ID参数为联系人Provider中的数据库BaseID,即哪一行
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(personUri);
startActivity(intent);

选择一个图片

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, 0);

调用Android设备的照相机,并设置拍照后存放位置

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment
.getExternalStorageDirectory().getAbsolutePath()+"/cwj", android123 + ".jpg"))); //存放位置为sdcard卡上cwj文件夹,文件名为android123.jpg格式
startActivityForResult(intent, 0);

自定义的Activity调用

Intent intent = new Intent();
intent.setClass(dataactivity.this, test3.class);
startActivity(intent);
要注意包的声明和权限修改,即AndroidManifest.xml的修改!

更多相关文章

  1. Android处理touch冲突的解决办法
  2. GIS的学习(二十四)android异步调用geoserver wms中的地图
  3. Android学习笔记十四之RelativeLayout相对布局
  4. android面試題2
  5. Android中使用AdapterViewFlipper实现自动播放的图库
  6. delphi xe5 android 调用照相机获取拍的照片
  7. 如何在MSM中实现Android震动系统
  8. setContentView( )方法
  9. Android(安卓)FrameWork——Binder机制详解(1)

随机推荐

  1. ListView设置分割线Divider样式
  2. 使用Android(安卓)Studio创建Android(安
  3. android 透明activity
  4. Android学习笔记之mainfest文件中android
  5. Android(安卓)HTTP
  6. android 内存管理
  7. [android警告]AndroidManifest.xml警告 N
  8. SeekBar自定义
  9. Android(安卓)的大牛的博客 提供给大家参
  10. Android(安卓)RelativeLayout 属性