android studio 基础TextView使用

本文介绍了在Android Studio中使用TextView的基本方法,包括直接在代码中设置文本、引用字符串资源文件中的文本、设置多行文本及省略号显示、在文本视图中添加小图片等内容。适合初学者快速掌握TextView的基本应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android studio 基础TextView使用

1、直接在代码中写

2、在项目的values目录下strings中写入

代码中调用

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:textSize="30sp"
    android:text="@string/test"

3、多行文本操作 android:lines 的属性是限制行数显示的

没有android:lines显示

有android:lines显示

增加 android:ellipsize="end" 属性可以看出文本框是否有文字超出

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:textColor="@color/purple_500"
    android:textSize="40sp"
    android:lines="2"
    android:ellipsize="end"
    android:text="左下角G左下角G左下角G左下角G左下角G左下角G左下角G左下角G左下角G"/>

配置小图片上去

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#bac"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="布局相对居中G"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left"
        android:textColor="@color/purple_500"
        android:textSize="40sp"
        android:lines="2"
        android:ellipsize="end"
        android:text="左下角G左下角G左下角G左下角G左下角G左下角G左下角G左下角G左下角G"/>
    <TextView
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:textSize="40sp"
        android:gravity="center"
        android:text="右下角G"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:textSize="30sp"
        android:text="@string/test"/>
    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:gravity="bottom|right"
        android:textSize="40sp"
        android:drawableTop="@mipmap/ic_launcher"
        android:text="左上角G"/>

</FrameLayout>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐为波

看着给就好了,学习写作有点累!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值