首页 技术 正文
技术 2022年11月15日
0 收藏 608 点赞 4,380 浏览 2702 个字

  我使用的IDE是Android Studio 2.1,虽然使用Eclipse也可以进行Android的开发,但是网上的大神大都推荐Android Studio,愿意了解的朋友可以参考知乎上关于Android Studio 和 Eclipse的讨论(网页链接:https://www.zhihu.com/question/21534929)。

  今天是正式学习Android开发的第一课,我从一些基本的接口组件的使用开始讲解,文中涉及到的一些接口组件我不会详细的去介绍,具体的介绍可以在网上搜索一下,这样也是为了避免语言的琐碎,提高学习效率。

1.TextView接口组件

    范例:<TextView android:id=”@+id/txtRsult”

             android:layout_width=”fill_parent”

             android:layout_height=”wrap_content”

             android:text=”程序运行结果”

        />

  以上程序代码的功能是增加一个名为txtRsult的TextView组件,该组件的功能是显示信息,用户无法编辑其中的文字。它的宽度设置为fill_parent,也就是填满它所在的外框,高度设置为wrap_content,也就是由文字的高度来决定,组件中会显示“程序运行结果”这个字符串。除了上面所用到属性,还有很多其他的属性,可以自行在网上搜索一下。

2.EditText接口组件

    范例:<EditText android:id=”@+id/edtSex”

             android:layout_width=”fill_parent”

                 android:layout_height=”wrap_content”

             android:inputType=”text”

             android:text=””

        />

  以上程序代码的功能是增加一个名为edtSex的EditText组件,该组件的功能是输入一段文件,再让程序读取该字符串。其中我重点介绍一下android:inputType属性,它是用来限制这个组件可以接受的字符类型,text代表任何字符都可以被接受,如果设置成number则只能输入0~9的数字字符。

3.Button接口组件

    范例:<Button android:id=”@+id/btnDoSug”

               android:layout_width=”fill_parent”

                   android:layout_height=”wrap_content”

            android:text=”运行”

        />

  接下来我们将上面所学习的三个接口组件进行整合,程序代码如下:

       <?xml version=”1.0″ encoding=”utf-8″?>

       <LinearLayout

             android:orientation=”vertical”

               android:layout_width=”fill_parent”

                   android:layout_height=”wrap_content” 

          >

        <TextView android:id=”@+id/txtRsult”

             android:layout_width=”fill_parent”

             android:layout_height=”wrap_content”

             android:text=”性别”

          />

         <EditText android:id=”@+id/edtSex”

             android:layout_width=”fill_parent”

                 android:layout_height=”wrap_content”

             android:inputType=”text”

             android:text=””

          />

          <TextView android:id=”@+id/txtRsult”

             android:layout_width=”fill_parent”

             android:layout_height=”wrap_content”

             android:text=”年龄”

          />   

          <EditText android:id=”@+id/edtSex”

             android:layout_width=”fill_parent”

                 android:layout_height=”wrap_content”

             android:inputType=”text”

             android:text=””

          /> 

          <Button android:id=”@+id/btnDoSug”

               android:layout_width=”fill_parent”

                   android:layout_height=”wrap_content”

            android:text=”健康建议”

              />   

          <TextView android:id=”@+id/txtRsult”

             android:layout_width=”fill_parent”

             android:layout_height=”wrap_content”

             android:text=”结果”

          /> 

         <LinearLayout/>

  特别说明一下,<LinearLayout>卷标是指定接口组件采线性顺序排列。它是一种接口组件的编排模式。

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,498
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,911
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,745
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,499
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,138
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,302