本章主要介绍主要的寻常较多使用的控件,包含TextView、EditView、ImageView、Button等。本章将介绍相关控件基本属性的使用,为以后章节的进阶学习提供基础。案例中引用的LinearLayout布局,可先不必深究。兴许章节将会具体介绍。

【博客专栏:http://blog.csdn.net/column/details/alearning.html

TextView

TextView控件的基本属性,android:layout_width 布局宽度android:layout_height 布局高度。这两个属性參数是必须的。

TextView 中android:layout_width与android:layout_height可供选择的參数:

  • match_parent   :匹配父控件大小(宽、高)【官方建议使用】
  • fill_parent    :填充父控件大小(宽、高)等效于match_parent
  • wrap_content   :包裹内容
TextView扩展的属性:
  • android:text指定控件的文本
  • android:gravity指定控件的基本位置
  • android:drawableLef指定text左边输出的drawable(如图片)
  • android:drawableRight指定text右边输出的drawable(如图片)
  • android:drawableTop指定text顶部输出的drawable(如图片)
  • android:drawableBottom指定text底部输出的drawable(如图片)
【布局文件】activity_textview.xml。
<?

xml version="1.0" encoding="utf-8"?

>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/tupiao"
android:gravity="center"
android:text="TextView_drawableLeft" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/tupiao"
android:gravity="center"
android:text="TextView_drawableRight" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/tupiao"
android:gravity="center"
android:text="TextView_drawableTop" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/tupiao"
android:gravity="center"
android:text="TextView_drawableBottom" /> </LinearLayout>

效果截图:


EditText

EditText控件,主要提供用户填写(输入)信息的接口作用。而之前介绍的TextView主要作用是信息的显示。

EditText中android:layout_width与android:layout_height可供选择的參数:

  • match_parent   :匹配父控件大小(宽、高)【官方建议使用】
  • fill_parent    :填充父控件大小(宽、高)等效于match_parent
  • wrap_content   :包裹内容

EditText扩展的属性:

  • android:text 指定控件的文本
  • android:gravity 指定控件的基本位置
  • android:password 指定文本以小点“•”显示
  • android:hint 指定Text为空时显示的文字提示信息
  • android:drawableLef 指定text左边输出的drawable(如图片)
  • android:drawableRight 指定text右边输出的drawable(如图片)
  • android:drawableTop 指定text顶部输出的drawable(如图片)
  • android:drawableBottom 指定text底部输出的drawable(如图片)
【布局文件】activity_edittext.xml。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="EditText" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="please input your message! " /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/tupiao"
android:gravity="center"
android:hint="please input your message! " /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/tupiao"
android:gravity="center"
android:text="EditText" /> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/tupiao"
android:gravity="center"
android:password="true"
android:text="EditText" /> </LinearLayout>

效果截图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFob2tpbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

ImageView

ImageView控件。主要提供图片显示的作用。但当对主要的控件了解清楚之后。就会发现这些基本控件非常多都能够通用适用,比如button的点击事件监听操作。

ImageView中android:layout_width与android:layout_height可供选择的參数:

  • match_parent   :匹配父控件大小(宽、高)【官方建议使用】
  • fill_parent    :填充父控件大小(宽、高)等效于match_parent
  • wrap_content   :包裹内容

ImageView扩展的属性:

  • android:src 指定前景drawable(如图片)
  • android:background 指定背景drawable(如图片)

注:background会依据ImageView组件给定的长宽进行拉伸。而src就存放的是原图的大小。不会进行拉伸。src是图片内容(前景)。background是背景,能够同一时候使用。

【布局文件】activity_imageview.xml。

<?xml version="1.0" encoding="utf-8"?

>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/image" /> <ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_dark"
android:src="@drawable/image" /> </LinearLayout>

效果截图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbWFob2tpbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

Button    ImageButton

Button控件。从命名本身就能够非常明了。提供button的控件。而ImageButton更显而易见是提供图片button。

Button/ImageButton中android:layout_width与android:layout_height可供选择的參数:

  • match_parent   :匹配父控件大小(宽、高)【官方建议使用】
  • fill_parent    :填充父控件大小(宽、高)等效于match_parent
  • wrap_content   :包裹内容

Button/ImageButton扩展的属性:

  • android:src 指定前景drawable(如图片)
  • android:text     对于ImageButton控件无效
  • android:background 指定前景drawable(如图片)

【布局文件】activity_button.xml。

<?

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button"
android:text="Button" /> <ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_with_text" /> </LinearLayout>

效果截图:


            Android经常使用的控件有非常多种,本章主要介绍这些较为经常使用的控件。以方便兴许章节的使用与为新知识点的引入做铺垫。本章的学习就此结束。敬请期待下一章节。

參考资料

1、http://www.uuton.com/post/3f493_1b8753
2、http://blog.163.com/allegro_tyc/blog/static/33743768201371301526104/


【ALearning】第三章 Android基本常见控件的更多相关文章

  1. 【风马一族_Android】第4章Android常用基本控件

    第4章Android常用基本控件 控件是Android用户界面中的一个个组成元素,在介绍它们之前,读者必须了解所有控件的父类View(视图),它好比一个盛放控件的容器. 4.1View类概述 对于一个 ...

  2. 介绍三个Android支持库控件:TabLayout+ViewPager+RecyclerView

    本文主要介绍如下三个Android支持库控件的配合使用: TabLayout:android.support.design.widget.TabLayout ViewPager:android.sup ...

  3. Android 中常见控件的介绍和使用

    1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...

  4. 第三章 续:时间控件(TimePicker)

    上一章,介绍了datetimepicker使用, 然而,当只需要时分秒的时候,它并不怎么理想,因此又找了一个单独的时间控制插件 现在介绍一个timepicker,用法差不多,但是它只是基于bootst ...

  5. Android设置常见控件点击效果

    一. Imageview的点击效果——图片稍微变暗突出点击效果 public class ClickImageView extends AppCompatImageView { public Clic ...

  6. 疯狂Android第二章:Adapter以及部分控件使用

    第二章 重点:1.理解View以及各种布局的优缺点,适用场景. 2.熟练掌握adapter原理与用法. 3.熟悉其它控件的基本使用方法. /////////////////////////////// ...

  7. 第三章Android移植平台工具介绍

    第三章Android移植平台工具介绍 进行 Android 移植的学习并不一定需要一款 Android 手机,但必须要有一款主流的开发板,开发板是用来进行嵌入式系统开发的电路板,包括中央处理器.存储器 ...

  8. 【Android】10.0 UI开发——如何编写程序界面、常见控件的使用

    ************************ 转载请注明出处:https://www.cnblogs.com/xiaofu007/p/10331880.html ***************** ...

  9. Android Material Design控件学习(三)——使用TextInputLayout实现酷市场登录效果

    前言 前两次,我们学习了 Android Material Design控件学习(一)--TabLayout的用法 Android Material Design控件学习(二)--Navigation ...

随机推荐

  1. 8.21 usaco

    summary:6 bzoj1692://后缀数组就行了O(nlogn)c[30]会RE...注意!!! #include<cstdio> #include<cstring> ...

  2. ehcache 分布式集群同步数据实例

    本文使用rmi方式,借鉴百度能搜到的文章,但是均不能做到数据同步,做了些改动完全没问题,更详细说明介绍百度即可.直奔主题,可运行的demo实例! 创建一个maven项目,配置pom pom.xml & ...

  3. jQuery树叶掉落特效代码

    代码使用方法 1.将index.html源文件中的JS设置代码插入到你的网页中 2.将style.css文件内容合并到你的页面样式表中 3.将jquery文件加载到你的页面中,请注意,这不是通用的jq ...

  4. SharePoint 2013 入门教程--系列文章

    转:http://www.cnblogs.com/jianyus/p/3381415.html 以下文章是自己在学习SharePoint的过程中,不断积累和总结的博文,现在总结一个目录,分享给大家.这 ...

  5. Entity Framework Code First级联删除

    如果我们要到一对主从表增加级联删除,则要在主表中的引用属性上增加Required关键字,如: public class Destination { public int DestinationId { ...

  6. Java多线程同步——生产者消费者问题

    这是马士兵老师的Java视频教程里的一个生产者消费者问题的模型 public class ProduceConsumer{ public static void main(String[] args) ...

  7. ADO.NET - 全面梳理

    转自:http://www.cnblogs.com/yangcaogui/archive/2012/06/09/2537086.html 目录: 简单的介绍下ADO.NET SqlConnection ...

  8. Visual Studio中的一些较大的文件的作用

    1.sdf 这些是工程中的中间,用于预编译等作用,最终可执行文件是不需要的,默认情况下,删除后重新编译还会生成.如果不需要,在Visual Studio里进入如下设置: 进入"Tools & ...

  9. 如何安装mysql-5.5.29-win32.zip

    1.windows下安装mysql-5.5.29-win32.zip: 1.解压缩,比如到d:\,为了方便,改一下路径,比如mysql2.开始/运行,输入cmd,回车进入命令行d:cd mysql\b ...

  10. 问题:关于坛友的一个定时重复显示和隐藏div的实现

    需求:打开页面只看到DIV2,等完秒数之后在显示DIV3.手动关闭DIV3后在重新数秒 我设置的间隔时间是3秒,代码如下: html+css: 1: <!DOCTYPE HTML> htm ...