Android TextView设置图标,调整图标大小
来源:互联网 发布:全国省市区街道数据库 编辑:程序博客网 时间:2024/05/01 15:26
在给TextView设置图标的时候,在xml文件里用
android:drawableStart="@drawable/icon"设置TextView图标,发现UI给的图标太大,太难看
但是在xml布局文件里无法修改图标大小,让UI重新弄图标又太麻烦
于是上网找看有没有可以修改大小的方法
最后发现在代码里动态设置TextView图标的两个方法
setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
以及
setCompoundDrawablesWithIntrinsicBounds(@DrawableRes int left, @DrawableRes int top, @DrawableRes int right, @DrawableRes int bottom)
两者的区别是,前者设置Drawable前,要通过Drawable.setBounds设置Drawable的长宽,后者不用。
所以我们可以在setBounds()时将图标设置成我们想要的大小
以下是实现代码
Drawable icon = getResources().getDrawable(R.drawable.icon);//setBounds(left,top,right,bottom)里的参数从左到右分别是//drawable的左边到textview左边缘+padding的距离,drawable的上边离textview上边缘+padding的距离//drawable的右边边离textview左边缘+padding的距离,drawable的下边离textview上边缘+padding的距离//所以right-left = drawable的宽,top - bottom = drawable的高icon.setBounds(0,0,40,44);mTextView.setCompoundDrawables(icon, null, null, null);
关于TextView的各种间距,如下图所示
阅读全文
0 0
- Android TextView设置图标,调整图标大小
- android 设置TextView的文本 上下左右 图标
- 设置TextView 图标
- textView 设置右图标
- bootstrap调整Glyphicons图标大小
- Launchpad图标大小怎么调整?
- bootstrap调整Glyphicons图标大小
- Android ListView 的布局图标大小设置
- Android系统状态栏图标间距大小的调整
- android系统图标大小
- android应用图标大小
- android图标大小规范
- android icon图标大小
- android 应用图标大小
- android app图标大小
- Android logo图标大小
- Mac Launchpad图标大小怎么调整
- app 图标大小,尺寸设置
- 论js的段位级别
- title: Servlet基础(一):servlet的生命周期
- 原声JS中indexOf()方法在数组中的应用一
- HTML5(2)__初识H5
- linux下PS1命令提示符设置
- Android TextView设置图标,调整图标大小
- 一个简易的表单校验插件wv.js
- 这个是在liunx上安装JDK,MAVEN,还有TOMCAT和Jenkins
- 五大流浏览器内核及其代表
- 专业量化交易从业人士如何看待传统的技术分析?
- Java反射详解
- POJ1128 Frame Stacking(拓扑排序+dfs)
- iOS Widget开发
- Machine Learning On Spark——基础数据结构(二)