Android基础到进阶UI爸爸级 TextView介绍+实例

1.在xml中创建并设置属性

咱们看上图说话。上图的文字显示多种多样,但是也仅包含TextView的部分功能,看看这多种多样的显示也是比较有意思的。

下面咱看看代码实践:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_margin=“@dimen/dimen_20”

android:orientation=“vertical”>

<TextView

android:id=“@+id/textView”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“TextView” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“@string/str_setting_color_size”

android:layout_marginTop=“@dimen/dimen_10”

android:textColor=“@color/color_ff0000”

android:textSize=“@dimen/text_size_20” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:drawableLeft=“@mipmap/ic_launcher”

android:layout_marginTop=“@dimen/dimen_10”

android:gravity=“center_vertical”

android:shadowColor=“@color/color_FF773D”

android:shadowDx=“30”

android:shadowDy=“-20”

android:shadowRadius=“2”

android:text=“右侧添加图片和使用阴影”

android:textColor=“@color/color_188FFF”

android:textSize=“@dimen/text_size_20” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:autoLink=“email|phone”

android:gravity=“center_vertical”

android:layout_marginTop=“@dimen/dimen_10”

android:text=“可点击跳转邮件:SCC5201314@qq.com\n可点击跳转电话:0215201314”

android:textColor=“@color/color_188FFF”

android:textSize=“@dimen/text_size_14” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:ellipsize=“end”

android:gravity=“center_vertical”

android:lineSpacingMultiplier=“1.2”

android:layout_marginTop=“@dimen/dimen_10”

android:maxLength=“2”

android:text="TxtView继承了View,它还是Button、EditText两个UI组件类的父类。它的作用是在用户界面上显示文本素。从功能上来看TextView就是个文本编辑器,只不过Android关闭的它的可编辑功能。如果需要一个可编辑的文本框,就要使用到它的子类Editext了,Editext允许用户编辑文本框中的内容。TextView和Editext它俩最大的区别就在于TextView不允许用户编辑文本内容,Editext允许用户编辑文本内容。

下面咱写几个实例来详细了解一下TextView的。"

android:textColor=“@color/color_188FFF”

android:textSize=“@dimen/text_size_14” />

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:background=“@color/color_ff0000”

android:layout_marginTop=“@dimen/dimen_10”

android:padding=“10dp”

android:text=“背景色红色的文本”

android:textColor=“@color/white” />

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“@dimen/dimen_10”

android:background=“@drawable/bg_tv_frame_red”

android:padding=“10dp”

android:text=“带着红色边框的文本” />

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“@dimen/dimen_10”

android:background=“@drawable/bg_tv_frame_gradient”

android:padding=“10dp”

android:textColor=“@color/white”

android:text=“带着边框和背景色渐变的文本” />

background设置边框的文件 android:background=“@drawable/bg_tv_frame_red”

<?xml version="1.0" encoding="utf-8"?>

带着边框和背景色渐变 android:background=“@drawable/bg_tv_frame_gradient”

<?xml version="1.0" encoding="utf-8"?>

<gradient

android:startColor=“@color/color_188FFF”

android:centerColor=“@color/color_FF773D”

android:endColor=“@color/color_ff0000”

android:type=“linear”

/>

2.在xml中创建,在代码中设置属性

  • 布局文件
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout_margin=“@dimen/dimen_20”

android:orientation=“vertical”>

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“下面是用代码实现效果”

android:textSize=“@dimen/text_size_18”

android:layout_marginTop=“@dimen/dimen_20”

android:layout_marginBottom=“@dimen/dimen_10”

android:textColor=“@color/black”

android:textStyle=“bold” />

<TextView

android:id=“@+id/tv_flag”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:textColor=“@color/color_188FFF”

android:layout_marginTop=“@dimen/dimen_10”

android:text=“给文本加划线”

android:textSize=“@dimen/text_size_18” />

<TextView

android:id=“@+id/tv_gradient”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“@dimen/dimen_10”

android:textColor=“@color/white”

android:text=“文字渐变是不是很神奇”

android:textSize=“@dimen/text_size_18” />

<TextView

android:id=“@+id/tv_bg”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“@dimen/dimen_10”

android:padding=“10dp”

android:text=“设置背景色”

android:textColor=“@color/white”

android:textSize=“@dimen/text_size_18” />

<TextView

android:id=“@+id/tv_size”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“@dimen/dimen_10”

android:textColor=“@color/color_ff0000”

android:text=“文字特别大小不一致” />

<TextView

android:id=“@+id/tv_onclick”

android:layout_width=“match_parent”

android:layout_marginTop=“@dimen/dimen_10”

android:layout_height=“wrap_content”

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

总结:

各行各样都会淘汰一些能力差的,不仅仅是IT这个行业,所以,不要被程序猿是吃青春饭等等这类话题所吓倒,也不要觉得,找到一份工作,就享受安逸的生活,你在安逸的同时,别人正在奋力的向前跑,这样与别人的差距也就会越来越遥远,加油,希望,我们每一个人,成为更好的自己。

  • BAT大厂面试题、独家面试工具包,

  • 资料包括 数据结构、Kotlin、计算机网络、Framework源码、数据结构与算法、小程序、NDK、Flutter

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

[外链图片转存中…(img-jtcpKcmb-1713838361585)]

总结:

各行各样都会淘汰一些能力差的,不仅仅是IT这个行业,所以,不要被程序猿是吃青春饭等等这类话题所吓倒,也不要觉得,找到一份工作,就享受安逸的生活,你在安逸的同时,别人正在奋力的向前跑,这样与别人的差距也就会越来越遥远,加油,希望,我们每一个人,成为更好的自己。

  • BAT大厂面试题、独家面试工具包,

  • 资料包括 数据结构、Kotlin、计算机网络、Framework源码、数据结构与算法、小程序、NDK、Flutter
    [外链图片转存中…(img-LKsP1ZK5-1713838361586)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值