TextView的使用
来源:互联网 发布:微信支付退款接口 php 编辑:程序博客网 时间:2024/06/07 07:09
TextView的主要作用就是显示一段文本信息
首先创建一个UI项目:
activity _main.xml中如下:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.uiwidgettest.MainActivity"> <TextView android:id="@+id/text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="This is TextView"/></RelativeLayout>
android:id—为当前控件定义一个唯一的标识符
android:layout_width—指定控件的宽度
android:layout_heigth—指定控件的高度
一般来说,Android中的控件都具有2种属性,它们的可选值有3种,下面我们来了解一下它们。
match_parent : 让当前控件的大小和父布局的大小一样。
wrap_content : 控件内容决定当前控件的大小
fill_parent : 与match_parent意义相同,目前官方更推荐后者。
当然除过以上的,也可自行对控件的宽和高进行指定控制(在这种方法中要注意,宽高与手机屏幕的适配)。
了解过后,运行程序。 效果如下:
现在修改一下代码:
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="This is TextView"/>
可以发现,android:gravity是用来指定文字的对齐方式,可选的值有很多,并且同时可以用“|”来指定多个值,上段代码中的center表示将对象居中对齐,也可以显示出TextView的宽度与屏幕是一样的。
TextView还有其他的属性,在需要用的时候可以去查询相关书籍。
- TextView的简单使用
- TextView的深入使用
- TextView标签的使用
- TextView的使用
- TextView的使用
- TextView的其他使用
- TextView的一些使用
- TextView 的使用
- TextView 的SpannableString使用
- 【总结】TextView的使用
- TextView的使用
- textView的学习使用
- TextView的实例使用
- Android TextView的使用
- TextView的使用
- TextView+Spinner的使用
- TextView的使用
- android TextView的使用总结
- Logistic回归(改进的随机梯度上升)
- struct结构体在c和c++中的区别
- jsp 初学01
- android ImageLoader加载本地图片的工具类
- 一步一步开发安卓应用 登录界面的功能 (LoginActivity)
- TextView的使用
- Android中的线程与线程池
- Git学习
- Qt读取excel
- 第三周项目1:个人所得税计算器
- 字符串连接
- Leetcode:160. Intersection of Two Linked Lists(JAVA)
- STM32的高级定时器里面死区的概念
- 打印JS