美文网首页Android
Android 之 TextView(文本)

Android 之 TextView(文本)

作者: izsm | 来源:发表于2018-11-09 14:37 被阅读0次

TextView 用于在界面上显示一段文本信息

属性:
<TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textSize="20sp"
        android:background="#111111"
        android:textColor="#ffffff"
        android:gravity="center"
        android:layout_gravity="center"/>
<!--
    id: 唯一标识符
    layout_width="match_parent: 表示当前元素的宽度和父元素一样宽
    layout_width="wrap_content: 表示当前元素的宽度只要能刚好包含里面的内容就行了

    layout_height="match_parent: 表示当前元素的高度和父元素一样高
    layout_height="wrap_content: 表示当前元素的高度只要能刚好包含里面的内容就行了
    
    text: 设置文本内容
    textSize: 设置文字的大小。
    textColor: 设置文字的颜色。
    background: 设置文本背景颜色
    gravity: 设置文字的对齐方式,可选值有 top、bottom、left、right、center 等,可以用竖线来同时指定多个值。center 效果等同于 "center_vertical 加 center_horizontal"
    layout_gravity: 设置文本对齐方式, 可选值有 top、bottom、left、right、center 等,可以用竖线来同时指定多个值。center 效果等同于 "center_vertical 加 center_horizontal"
    -->
效果:
屏幕快照 2018-11-09 下午2.36.48.png

相关文章

网友评论

    本文标题:Android 之 TextView(文本)

    本文链接:https://www.haomeiwen.com/subject/xrqoxqtx.html