---
title: "android Button,textView 等控件设置控件内嵌周围图片使用方法"
author: "caryt"
date: "2013-12-16T15:43:00Z"
tags: []
slug: "android-button-textview"
draft: false
lastmod: "2014-04-25T10:57:11Z"
id: 2054446
url: "https://caryt.iteye.com/blog/2054446"
---

# android Button,textView 等控件设置控件内嵌周围图片使用方法

....................................................................................................................................................................................................................................

# 1：在布局中直接设置：

# android:drawableLeft|Right|Top|Bottom

android:drawablePadding="10dp"//图片与控件文字内容距离设置

# 2：在代码中动态设置：Drawable img\_right，img\_left,img\_top,img\_bottom;

# a:获取drawable：img\_right=getResources().getDrawable(R.drawable.img\_right);......

# b:设置图片（必须设置，不设置，图片不显示哦！）：

img\_right.setBounds(0, 0, img\_right.getMinimumWidth(), img\_right.getMinimumHeight());

# c:button.setCompoundDrawables(null,null,img\_right,null)；

.................................................................................................................................................................................................................................................