Android
1、TextView
a) 属性设置
TextView有多个属性
b) Android:autoLink
设置显示文本的格式、
autoLink属性 web email phone map all
2、ImageView的功能和用法
ImageView继承View组建,它的主要功能是用于显示图片,任何Drawable对象都可以使用ImageView来显示。
Android:adjustViewBounds(setAdjustViewBounds(boolean))设置ImageView是否调整自己的边界来保持所显示图片的长宽比。
Android:maxHeight(setMaxHeight(int))设置ImageView的最大高度
Android:maxWidth(serMaxWidth(int))设置ImageView的最大宽度
Android:scaleType (setScaleType(ImageView.ScaleTYpe)设置所显示的图片如何缩放或移动以适应ImageView的大小
Android:scr(setImageResource(int))设置ImageView所显示的Drawable对象的ID
3、自动完成文本框(AutoCompleteTextView)的功能和用法
自动完成文本框从EditText派生而出,它比普通编辑框多了一个功能:当用户输入一定字符之后,自动完成文本框会显示一个下拉菜单,供用户从中选择,当用户选择某个菜单项之后,AutoCompleteTextView按用户选择自动填写该文本框。
AutoCompleteTextView除了可以使用EditText提供的XML属性和方法之外,还支持设置出现在下来菜单中提示标题,设置用户至少输入几个字符才会显示提示,设置下来菜单的高度,设置下拉菜单与文本框之间的水平偏移,设置下来菜单与文本之间的垂直偏移,设置下拉菜单的宽度,设置下拉菜单的背景。
4、 带边框的TextView
自定义带边框的TextView
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class BorderTextView extends TextView {
public BorderTextView(Context context, AttributeSet attr) {
super(context,attr);
}
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(android.graphics.Color.GREEN);
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);
}
}
<cn.liuyan.activity.BorderTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="30dp"
android:text="dasdasdsadas"
/>
5、EditText中回车键的使用
XML
<EditText
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="text1" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Button" />
JAVA
et.setOnKeyListener(this);
…
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
btn.setText(et.getText());
et.setVisibility(View.GONE);
btn.setVisibility(View.VISIBLE);
}
return true;
}
6、
代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱"
android:textSize="19dp" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 用户名"
android:textSize="19dp" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:inputType="text|textPersonName" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 密 码"
android:textSize="19dp" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确认密码"
android:textSize="19dp" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 验证码"
android:textSize="19dp" />
<EditText
android:layout_width="90dp"
android:layout_height="wrap_content"
android:inputType="text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/yzm" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/huanYiGe"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shengMing" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="确 定" />
</LinearLayout>
</LinearLayout>