今天主要讲解Android的两个组件,TextViewEditText。这两个组件非常常见,从第一天的HelloWord就开始接触这两个组件,这两个组件极其常用,但是功能又是非常强大的。有些功能在平时遇见可能也没有太在意,但是如果在开发的过程中能用到组件里面的功能是非常有好处的。虽然简单,但是确是非常重要的。

TextView

1、属性设置:

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textColor="#00FF00"

android:padding="30dp"

android:textSize="30dp"

//android:layout_margin="10dp"

android:text="@string/hello"/>

设置了字体的颜色,边距,文本大小等属性,其中"layout_width"属性和"layout_margin"有冲突,使用时需要注意

2、AndroidautoLink

设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接。可选值为(web/email/phone/map/all

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns: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="fill_parent"

android:layout_height="wrap_content"

android:autoLink="web"

android:text="@string/webURL"/>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:autoLink="map"

android:text="@string/map"/>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:autoLink="phone"

android:text="@string/phone"/>

<TextView

android:id="@+id/tvHtml"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:autoLink="all"

android:text="@string/autoAll"/>

</LinearLayout>

注意:

android:autoLink=”email”:会出现unsupportedaction,可能是模拟器bug,须探究

另外使用Html.fromHtml时,超链接只具备外观,不能跳转

3、*.9.patch

1)他是一个针对png图片的处理工具,能够生成一个“*.9.patch”的图片,所谓“*.9.patch”这里是Android里所支持的一种特殊的图片格式,用它可以实现部分拉伸,如果不处理直接用png图片就会失真,拉伸出不正常的现象出来。

2)启动:首先在Android的SDK的路径的tools中,你会找到一个“draw9patch.bat”,点击打开如下图所示:

导入一张png图片,然后进入操作区域,如下图所示

序列①:在拉伸区域周围用红色边框显示可能会对拉伸后的图片产生变形的区域,如果完全消除该内容则图片拉伸后是没有变形的,也就是说,不管如何缩放图片显示都是良好的。(实际试发现NinePatch编辑器是根据图片的颜色值来区分是否为badpatch的,一边来说只要色差不是太大不用考虑这个设置。)

序列②:区域是导入的图片,以及可操作区域。

序列③:这里zoom:的长条bar是对导入的图放大缩小操作,这里的放大缩小只是为了让使用者更方便操作,毕竟是对像素点操作比较费眼,下面的patchscale是序列④区域中的三种形态的拉伸后的一个预览操作,可以看到操作后的图片拉伸后的效果。

序列④:区域这里从上到下,依次为:纵向拉伸的效果预览、横向拉伸的效果预览,以及整体拉伸的效果预览

序列⑤:这里如果你勾选上,那么当你鼠标放在②区域内的时候并且当前位置为不可操作区域就会出现lock的一张图,就是显示不可编辑区域;

序列⑥:这里勾选上,那么在④区域中你就会看到当前操作的像素点在拉伸预览图中的相对位置和效果。

序列⑦:在编辑区域显示图片拉伸的区域;

3)对图片的操作

上方和左边的黑色像素是我手动操作的地方,选择上方区域是为了横向拉伸的时候选取的像素点,左边则是纵向拉伸

4)使用“*.9.png”的好处

通过“*.9.patch”处理过的图片可以减少内存,而且还可以减少代码量,虽然手机趋向于智能了,但是毕竟手机的内存和容量有限,身为移动开发者的我们必须对此很重视,通过此方法处理过的图片就可以帮我们省去很多内存和容量

4、带边框的TextView

Paintpaint=newPaint();

paint.setColor(android.graphics.Color.RED);

canvas.drawLine(0,0,this.getWidth()-1,0,paint);

canvas.drawLine(0,0,0,this.getHeight()-1,paint);

canvas.drawLine(this.getWidth()-1,0,this.getWidth()-1,this.getHeight()-1,paint);

canvas.drawLine(0,this.getHeight()-1,this.getWidth()-1,this.getHeight()-1,paint);

EditText:

1、输入特定字符:

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:password="true"

android:digits="01234"/>//只能输入数字

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:digits="abcd"/>//只能输入拼音

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:inputType="datetime"/>//时间日期

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:inputType="textEmailAddress"/>//email地址

2、自动完成输入内容的组件

用到的方法:AutoCompleteTextViewMultiCompleteTextView

<AutoCompleteTextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/autotx"

/>

<MultiAutoCompleteTextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/mautotx"

/>

更多相关文章

  1. Unity与EasyAR
  2. Android在开发中的实用技巧之ExpandableListView简单实现商品列
  3. Android(安卓)微信分享,无需那么麻烦。
  4. [置顶] Android图片异步加载之Android-Universal-Image-Loader
  5. android 9PNG图片制作
  6. Android(安卓)高仿微信发朋友圈浏览图片效果
  7. android 显示图片的指定位置图像 ImageView ImageButton
  8. Android(安卓)图片内存溢出(Out of Memory)
  9. android批量文件上传(android批量图片上传)

随机推荐

  1. android手机与arm平台实现无线视频监控
  2. Android(安卓)Stuido如何查看快捷键冲突?
  3. Android开源项目分包方式学习(eoe、oschin
  4. Android(安卓)Studio JNI javah遇到的问
  5. Android(安卓)AndroidProgressLayout:加载
  6. android中的反编译
  7. Android(安卓)和 iOS 版 Quickoffice 都
  8. 【Android(安卓)开发】:UI控件之 ImageVie
  9. android手机短信发送
  10. Android(安卓)init 启动过程分析(一)