Android UI控件系列:TextView(文本框)
- 作者: 小明的麻麻
- 来源: 51数据库
- 2020-08-16
TextView比较简单,不能够用来进行编辑,只能够用来显示信息
布局文件里的一些常用的XML属性
android:gravity—用来设置控件内文本的对齐方式
android:layout_gravity—相对于父控件来说,用于设置控件的对齐方式
android:text—用来设置控件文本信息
android:layout_width—用来设置控件的宽度
android:layout_height—用来设置控件的高度
android:background—用来设置控件的背景色
android:textColor—用来设置控件内文本的颜色
android:textSize—用来设置控件的文本字体大小
android:width和android:height—功能与android:layout_width相似
区别:
android:layout_width只能设置fill_parent(横向填充整个屏幕)或
wrap_content(横向填充控件本身大小)
android:width设置具体控件的横向大小 单位是像素
例如:TextView显示
main.xml布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:orientation="vertical" ? ? android:layout_width="fill_parent" ? ? android:layout_height="fill_parent" ? ? > <TextView ? ? android:layout_width="fill_parent" ? ? android:layout_height="wrap_content" ? ? android:text="@string/hello" ? ? /> </LinearLayout>
string.xml文件
<?xml version="1.0" encoding="utf-8"?> <resources> ? ? <string name="hello">Hello World, MyTestView!</string> ? ? <string name="app_name">MyTestView</string> </resources>
MyTextView.java文件
package org.loulijun.MyTestView;
import android.app.Activity;
import android.os.Bundle;
public class MyTestView extends Activity {
? ? /** Called when the activity is first created. */
? ? @Override
? ? public void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.main);
? ? }
}
运行结果:

推荐阅读
热点文章
android中Bitmap用法(显示,保存,缩放,旋转)实例分析
12
android 仿微信聊天气泡效果实现思路
1
Android的尺度,drawable-xxxxxxx
2
Codeforces Round #656 (Div. 3) (C、D题)
1
Android之handler异步消息处理机制解析
6
GridView中图片显示出现上下间距过大,左右图片显示类似瀑布流的问题
0
AsyncTask的简单使用
5
两个简单Fragment之间的通信(三种方式)
18
uboot修改设置boot参数命令
41
android中实现从相册中一次性获取多张图片与拍照,并将选中的图片显示出来
2
