Android多种跑马灯的实现方法

wyh_Files 2019-08-04 06:08:54
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hwe_xc/article/details/50906220 我们知道,TextView控件一般是用来显示文本的,而图片一般是用ImageView控件来显示。 那TextView能否显示图片呢?答案是肯定的!下面列出常见的4种方式。 XML文件中指定属性值 这种方式应该是最常用的了,在TextView的左上右下显示图片,可用 android:drawableLeft android:drawableTop android:drawableRight android:drawableBottom 比如我们要在TextView的顶部设置图片,代码如下: <TextView android:id="@+id/textview_01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_launcher" android:text="hello_world" /> 1 2 3 4 5 6 这种显示方式图片跟文本是居中对齐的,此种方式对应的方法是setCompoundDrawablesWithIntrinsicBounds: mTextView01.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.ic_launcher, null), null, null); 1 2 效果图: 如果觉得图片离文字太近,也可以设置他们之间的间距,xml或者代码中都可以实现: android:drawablePadding="10dp" 1 或者 mTextView01.setCompoundDrawablePadding(10); 1 通过解析HTML来显示图片 这种方式可以显示项目中的图片、本地SDCARD和网络的图片,当然网络的图片必须先下载到本地然后显示。 显示项目中图片 看代码 // 第二种方式:显示项目中的图
...全文
152 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧