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 UI控件系列:TextView(文本框)的内容,更多相关内容请关注PHP中文网(www.php.cn)!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号