android textview 常用属性id,Android-TextView 控件常用属性以及基本用法

前言

这是我第一次写博客,第一次的笔记,不足之处多谅解。开门见山,这一篇博客主要讲一下在Android开发中,UI控件TextView的一些使用方式,主要介绍一些常用的属性,加上一些实例,希望大家看了后能够掌握其基本用法。

【基本属性】

【设置ID】

android:id="@+id/tv"     //id:自定义 用于关联控件,然后对此控件的操作使用

【设置宽度和高度】

android:layout_width="wrap_content"

android:layout_height="wrap_content"

af7f468cf6bf1e581c50b3cc5e273897.png

第一个 自适应:根据宽度/高度 自动匹配

第二个 充满:根据宽度/高度 充满全屏

【设置背景颜色】

android:background="#dddddd"

可以填充各种颜色,也可以插入图片

例如:

9a61091f25627ec46b7264d86086b00a.png

【插入图片方向】

android:drawableLeft="@drawable/ic_launcher_foreground"

android:drawableBottom=""

android:drawableRight=""

android:drawableStart=""

android:drawableEnd=""

android:drawableTop=""

这个不多说了 top就是在textview上面 bottom就是下面

【文字方向:居中、左右上下。。。】

android:gravity="center"

3d6b899cfa2ba7cb85ec14ae8e804e0b.png

【设置字体、字体颜色、字体大小、字体加粗】

a9988c9af918301fce04f45feae0f102.png

android:textStyle="bold"

android:text="这是Textview"

android:textColor="#ff00feee"

android:textSize="33sp"

text:设置文字; textColor:设置字体颜色,前两位透明度;textSize:设置字体大小 用sp为单位

textstyle:字体样式 bold:加粗 italic:斜体

android:id="@+id/tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#dddddd"

android:drawableLeft="@drawable/ic_launcher_foreground"

android:ellipsize="end"

android:gravity=""

android:textStyle="bold"

android:text="这是Textview"

android:textColor="#ff00feee"

android:textSize="33sp"/>

下面是效果图

077a5ca70a4abb78d87c13d7c6d85320.png

下面简单的写下代码进行修改

023964651ff34537122bd9d3d2a6863b.png

【效果图】

1e144ca40c57b1f5211d4bb6e8aa8835.png

Android-Textview 控件简单实用就差不多这些了

原文:https://www.cnblogs.com/MrChen-/p/10295219.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现英文两端对齐,可以使用Android中的JustifiedTextView件。JustifiedTextView是一个自定义TextView,它可以将文本对齐到视图的左右边缘。这个件使用了一个开源的库android-textview-align库,你可以在项目中引入该库,也可以将其源代码拷贝到你的项目中。 下面是使用JustifiedTextView件实现英文两端对齐的步骤: 1. 在项目中添加android-textview-align库。 2. 在布局文件中使用JustifiedTextView件。 3. 在代码中设置文本和对齐方式。 示例代码如下: ```xml <com.codesgood.views.JustifiedTextView android:id="@+id/justified_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello world, this is a sample text to demonstrate the usage of JustifiedTextView." /> ``` ```java JustifiedTextView justifiedText = (JustifiedTextView) findViewById(R.id.justified_text); justifiedText.setText("Hello world, this is a sample text to demonstrate the usage of JustifiedTextView."); justifiedText.setAlignment(Paint.Align.LEFT); ``` 在上面的代码中,我们将对齐方式设置为左对齐,这将使文本左右两端对齐。你也可以将对齐方式设置为中央对齐、右对齐等。 需要注意的是,JustifiedTextView件不支持在文本中使用HTML标记,如果你需要在文本中使用HTML标记,可以使用Android中的Html.fromHtml()方法来解析HTML标记,然后将解析后的文本设置到JustifiedTextView件中。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值