android 实现表格横向混动_Android图文混排实现方式详解

在使用TextView的时候,我们经常需要在TextView中进行图文混排,比如在QQ中聊天的消息中的表情,底部tab图标等。

一、场景

二、实现方式

Android官方对TextView的图文混排提供了支持,我们可以从以下三种方式实现TextView的图文混排:

1.在TextView中使用Compound Drawable属性;

2.在TextView中使用Spannable多样式显示;

3.在TextView中显示HTML文本。

三、drawable属性

在TextView中使用Compound Drawable属性可以在文字的上下左右放置drawable,效果如下:

一共有两种方式可以实现:XML布局设置和Java代码设置。

1. xml布局

android:gravity="center"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="查看新的内容"

android:textSize="18sp"

android:drawablePadding="10dp"

android:drawableLeft="@drawable/arrow"/>

android:drawableLeft

在文字左边设置图片

android:drawableTop

在文字上边设置图片

android:drawableRight

在文字右边设置图片

android:drawableBottom

在文字下边设置图片

android:drawableStart

API 17后生效,LTR时在左边,RTL时在右边

android:drawableEnd

API 17后生效,LTR时在右边,RTL时在左边

android:drawablePadding

图片和文字的间距

2. java代码

textView = (TextView) findViewById(R.id.textView);

Drawable drawable = getResources().getDrawable(R.drawable.see);

drawable.setBounds(0,0

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值