Android应用程序:简单拨号器
2015-08-11 17:47
513 查看
新建一个工程:Android Application Project,本人命名为tel。
MainActivity.java中的代码如下:
补充说明:
android:orientation="vertical" 表示竖直方式对齐。只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
android:orientation="horizontal"表示水平方式对齐。只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
android:layout_width="fill_parent"定义当前视图在屏幕上可以消费的宽度,fill_parent即填充整个屏幕。
设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。
android:layout_height="wrap_content":随着文字栏位的不同而改变这个视图的宽度或者高度。设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。
layout_weight: 用于给一个线性布局中的诸多视图的重要度赋值.所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。
举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,则剩余空间的三分之一分给第一个,三分之二分给第二个。
android:phoneNumber="true" :当前组件只能输入数字
MainActivity.java中的代码如下:
package com.example.tel; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { private Button button; private EditText call; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去除标题栏 this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); call = (EditText) findViewById(R.id.telphone); button = (Button) findViewById(R.id.b); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub call = (EditText) findViewById(R.id.telphone); String tel = call.getText().toString().trim(); Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+tel)); startActivity(intent); } }); } }activity_main.xml中的代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E6E6E6" > <!-- <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#00ffff" > 此处是设置的一个页面头部 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="拨号器" android:textColor="@android:color/white" android:textSize="18dp" /> </RelativeLayout> --> <ImageView android:id="@+id/image_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_marginTop="60dp" android:src="@drawable/ic_launcher"/> <EditText android:id="@+id/telphone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="请输入手机号" android:paddingLeft="10dp" android:phoneNumber="true" /> <Button android:id="@+id/b" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/login_button_nor" android:text="拨打" /> </LinearLayout>在AndroidManifest.xml中添加代码:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
补充说明:
android:orientation="vertical" 表示竖直方式对齐。只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
android:orientation="horizontal"表示水平方式对齐。只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
android:layout_width="fill_parent"定义当前视图在屏幕上可以消费的宽度,fill_parent即填充整个屏幕。
设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。
android:layout_height="wrap_content":随着文字栏位的不同而改变这个视图的宽度或者高度。设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。
layout_weight: 用于给一个线性布局中的诸多视图的重要度赋值.所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。
举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,则剩余空间的三分之一分给第一个,三分之二分给第二个。
android:phoneNumber="true" :当前组件只能输入数字
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories