设置drawable图片
google官方建议在textView和imageView挨着的时候,建议使用drawable来显示图片
第一个方法:setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)
api原文为:
|
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds. 意思大概就是:可以在上、下、左、右设置图标,如果不想在某个地方显示,则设置为null。图标的宽高将会设置为固有宽高,既自动通过getIntrinsicWidth和getIntrinsicHeight获取。——笔者翻译 |
button = (RadioButton) group.getChildAt(i);
Resources res = TabTest.this.getResources();
Drawable myImage = res.getDrawable(R.drawable.home);
button.setCompoundDrawablesWithIntrinsicBounds(null, myImage, null, null);
第二种方法:setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
api原文为:
|
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables must already have had 意思大概就是:可以在上、下、左、右设置图标,如果不想在某个地方显示,则设置为null。但是Drawable必须已经setBounds(Rect)。意思是你要添加的资源必须已经设置过初始位置、宽和高等信息。——笔者翻译 |
这下就明白了,这个方法要先给Drawable设置setBounds(x,y,width,height);
x:组件在容器X轴上的起点 y:组件在容器Y轴上的起点 width:组件的长度 height:组件的高度。
如代码:
1 Resources res = TabTest.this.getResources();
2 Drawable myImage = res.getDrawable(R.drawable.home);
3 myImage.setBounds(1, 1, 100, 100);
4 button.setCompoundDrawables(null, myImage, null, null);
设置drawable图片的更多相关文章
- Android开发 从代码里设置Drawable图片不显示的问题
问题描述 我们从代码里获得Drawable在设置给View时会发现,图片不显示的问题.比如如下代码: Drawable drawable = getResources().getDrawable(R. ...
- textview设置drawable
textview可以在上下左右四个方向添加图片,同时也可以动态改变这些图片: 下面有我写的一个例子: 在xml文件中: <TextView android: ...
- [Netbeans]为面板设置背景图片
与AndroidStudio等类似IDE不同,在Netbeans开发桌面程序时,不可以直接通过src=@drawable 等方法为窗口设置背景图片.这里介绍一种简便的方法: 1:首先,拖动一个面板到f ...
- Android代码中设置背景图片
//设置背景图片 String picfile= Environment.getExternalStorageDirectory() + "/pdp/pdp.png" ...
- 使用装饰器模式动态设置Drawable的ColorFilter
使用装饰器模式动态设置Drawable的ColorFilter 欢迎各位关注我的新浪微博:微博 转载请标明出处(kifile的博客) 非常多时候我们都希望Android控件点击的时候,有按下效果,选中 ...
- img只显示图片一部分 或 css设置背景图片只显示图片指定区域
17:14 2016/3/22img只显示图片一部分 或 css设置背景图片只显示图片指定区域 background-position: 100% 56%; 设置背景图片显示图片的哪个坐标区域,图片左 ...
- 为窗体设置背景图片-UI界面编辑器(SkinStudio)教程
1.1. 为窗体设置背景图片 在窗体的Background属性中选择图片设置为窗体背景图片
- 新浪微博客户端(32)-设置相册图片的contentMode
DJStatusPhotoView.m #import "DJStatusPhotoView.h" #import "UIImageView+WebCache.h&quo ...
- UIView 设置背景图片
http://blog.csdn.net/qijianli/article/details/7777268 项目中,可能需要我们为某个视图设置背景图片,而API中UIView没有设置背景图片的方法,那 ...
随机推荐
- 利用电话管理器TelephonyManager获取网络和SIM卡信息
import java.util.ArrayList;import java.util.HashMap;import java.util.Map; import android.os.Bundle;i ...
- 如何使用Weave以及Docker搭建Nginx反向代理/负载均衡服务器
Hi, 今天我们将会学习如何使用 Weave 和 Docker 搭建 Nginx 的反向代理/负载均衡服务器.Weave 可以创建一个虚拟网络将 Docker 容器彼此连接在一起,支持跨主机部署及自动 ...
- IoTimerInLineHook
#ifndef CXX_IOTIMERINLINEHOOK_H # include "IoTimerInlineHook.h" #endif ULONG32 SSDT_NtOpen ...
- javascrip自定义对象的方式
对象初始化方式(也叫json对象创建方式) <script type="text/javascript"> var User = { name:"paul&q ...
- Oracle练习题20~33
20.查询score中选学多门课程的同学中分数为非最高分成绩的记录. 21. 查询成绩高于学号为“109”.课程号为“3-105”的成绩的所有记录. 22.查询和学号为108的同学同年出生的所有学生的 ...
- POJ 3274 Gold Balanced Lineup 哈希,查重 难度:3
Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow ...
- soap
sudo apt-get update apt-get install php-soapphp-config --configure-options --enable-soap php -i | gr ...
- TStringList 的Sorted属性
1 .设置 sorted := true; 2.添加数据 add('3');add('4');add('1'); showmessage(commatext);// 1,3,4 3.再修改Sorted ...
- HDFS权限问题
HDFS权限问题 Win下Eclipse提交hadoop程序出错:org.apache.hadoop.security.AccessControlException: Permission denie ...
- Xcode如何查看内存中的数据
在 debug 模式下如何在断点处,查看字符指针变量内存中的值,像vs2008的调试工具一样的内存查看器,现在只能查看第一个内存中的值可以在输出窗口采用gdb命令:x /nfu <addr&g ...