Android的TextView基本属性

Android的TextView基本属性

一、 说明

本文主要讲一些Android的TextView的一些基本的属性。

二、 所用工具

Android Studio

三、 TextView的基本属性说明
1. id:为TextView设置一个组件id,根据id,我们可以在Java代码中通过findViewById()的方法获取到该对象,然后进行相关属性的设置,使用RelativeLayout(相对布局)时,参考组件要使用id!
2. layout_width:组件的宽度

可选值:
"wrap_content ",控件显示的内容多大,控件就多大。
"match_parent(fill_parent) ",填满该控件所在的父容器;
也可以设置成特定的大小,设置成了300dp等等。

3. layout_height:组件的高度

可选值:
"wrap_content ",控件显示的内容多大,控件就多大。
"match_parent(fill_parent) ",填满该控件所在的父容器;
也可以设置成特定的大小,设置成了300dp等等。

4. gravity:设置控件中内容的对齐方向

常用值:
center:居中对齐
top:顶部对齐
buttom:底部对齐
left:左边对齐
right:右边对齐

5. textAlignment:设置字体的对齐方向

常用值:
Center:居中对齐
textStart:左边对齐
textEnd:右边对齐

6. text:设置显示的文本内容,一般我们是把字符串写到strings.xml文件中,然后通过@String/xxx取得对应的字符串内容的
7. textColor:设置字体颜色,一般我们是把字符串写到colors.xml文件中,然后通过@color/xxx取得对应的颜色的
8. textStyle:设置字体风格

可选值:
normal(无效果)
bold(加粗)
italic(斜体)

9. textSize:设置字体大小!
10. background:控件的背景颜色,可以理解为填充整个控件的颜色,也可以是图片!
四、 代码
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/ll_main_content"
       android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:id="@+id/tv_test"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="测试页面"
            android:textSize="50sp"
            android:textColor="#000000"
            android:background="#ffffff"
            android:gravity="center"
            android:textStyle="bold"
            android:textAlignment="center">
        </TextView>
    </LinearLayout>
</LinearLayout>

五、 效果图
在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值