转载请注明出处:http://blog.csdn.net/droyon/article/details/37564419

非常多人有如标题所述的需求,并且大多数人採用了自己定义组件攻克了需求,事实上还能够有更“懒”的方法。

1、先附效果图:

2、方案。

首先,Activity.java

public class MainActivityTest extends Activity{

	@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
} }

其次,xml布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" > <Button
android:id="@+id/btn_ok0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_launcher"
android:text="@string/hello_world" /> <Button
android:id="@+id/btn_ok1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/ic_launcher"
android:text="@string/hello_world" /> <Button
android:id="@+id/btn_ok2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_launcher"
android:text="@string/hello_world" /> <Button
android:id="@+id/btn_ok3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_launcher"
android:text="@string/hello_world" /> </LinearLayout>

3、解析。

关键代码就是布局文件里的android:drawableBottom,drawableBottom这个属性(attr)属于TextView解析的范畴,我们使用的Button,它继承自TextView,因而可以使用此属性完毕Drawable的布局。

在Button上、下、左、右位置加入图片和文字的更多相关文章

  1. js实现Mac触摸板双指事件(上/下/左/右/放大/缩小)

    前言 这几天在修复一个web问题时,需要捕获Mac触摸板双指事件(上.下.左.右.放大.缩小),但发现并没有现成的轮子,还是要自己造. 例如:jquery.mousewheel.js(添加跨浏览器的鼠 ...

  2. iOS 通用button 上图下字

    UIButton *first = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kHeight(80), kHeight(80))]; [firs ...

  3. iOS Button 上文字图片位置的设置

    1. 添加图片+文字/文字+图片 ,不分前后,图片默认在文字前边 加空格隔开 UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake ...

  4. 用C#代码实现类似QQ窗体的“上、左、右”停靠功能

    大家都知道QQ有一个自动停靠功能,即“上.左.右”,当你把窗体拖到屏幕边缘,然后移开鼠标它会自动缩放,然后只显示一小小点出来,我们仔细观察会发现其实它只露3像素左右的边缘,当你鼠标移上去它又会伸出来, ...

  5. UIButton图片文字控件位置自定义(图片居右文字居左、图片居中文字居中、图片居左文字消失等)

    在开发中经常会碰到需要对按钮中的图片文字位置做调整的需求.第一种方式是通过设置按钮中图片文字的偏移量.通过方法setTitleEdgeInsets和setImageEdgeInsets实现 代码如下: ...

  6. Atitit.获得向上向下左的右的邻居的方法 软键盘的设计..

    Atitit.获得向上向下左的右的邻居的方法 软键盘的设计.. Left right可以直接使用next prev.. Up down可以使用pix 判断...获得next element的posit ...

  7. 全栈开发工程师微信小程序-上(下)

    全栈开发工程师微信小程序-上(下) icon 图标 success, success_no_circle, info, warn, waiting, cancel, download, search, ...

  8. JavaScript--获取页面盒子中鼠标相对于盒子上、左边框的坐标

    分析: 外层边框是浏览器边框,内部盒子是页面的一个盒子,绿点是盒子中鼠标的位置.鼠标相对盒子边框的坐标=页面中(注意不是浏览器)鼠标坐标-盒子相对于浏览器边框的偏移量 第一步:求浏览器边框位置 x=e ...

  9. button上加上图片的两种方式

    ////  ViewController.m//  UIButtonDemo////  Created by hehe on 15/9/15.//  Copyright (c) 2015年 wang. ...

随机推荐

  1. Swift - 时间控制器NSTimer(每隔一定时间执行某个函数)

    时间控制器NSTimer可以实现定时器功能,即每隔一定时间执行具体函数,可以重复也可以只执行一次. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 cl ...

  2. 存储的几个LUN问题

    存储的几个LUN问题 . ---整理自EMC论坛 1. Linux中如何识别LUN?(AIX是否也差不多) 当创建好LUN并建好storage group后,主机(linux)可以直接用fdisk - ...

  3. Java的HashCode

    ·HashCode就是根据对象存储在内存的地址计算出的一个值.这个值可以标识这个对象的位置.也可以对比两个引用变量是否指向同一个对象. ·String重写了hashCode方法——改为根据字符序列计算 ...

  4. C++ Primer 学习笔记_76_模板和泛型编程 --模板定义[继续]

    模板和泛型编程 --模板定义[续] 四.模板类型形參 类型形參由keywordclass或 typename后接说明符构成.在模板形參表中,这两个keyword具有同样的含义,都指出后面所接的名字表示 ...

  5. QT 多线程程序设计(也有不少例子)

    QT通过三种形式提供了对线程的支持.它们分别是,一.平台无关的线程类,二.线程安全的事件投递,三.跨线程的信号-槽连接.这使得开发轻巧的多线程Qt程序更为容易,并能充分利用多处理器机器的优势.多线程编 ...

  6. 成功为Android系统配上了GNU开发环境

             单击此处获得本文的最新更新 经过一周的艰苦努力,成功为我的小米2手机适配上了全功能的GNU开发环境,完全兼容GNU/LINUX(Android自带的bionic.linker真心不好 ...

  7. A Game of Thrones(20) - Eddard

    Eddard Stark rode through the towering bronze doors of the Red Keep sore, tired, hungry, and irritab ...

  8. java 状态模式 解说演示样例代码

    package org.rui.pattern; import junit.framework.*; /** * 为了使同一个方法调用能够产生不同的行为,State 模式在代理(surrogate)的 ...

  9. 黑马程序员:Java基础总结----类加载器

    黑马程序员:Java基础总结 类加载器   ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 类加载器 Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个 ...

  10. Android相关

    wifi密码:因为我们安卓系统的手机无线账号数据是储存在一个文件里的,那就是 /data/misc/wifi/wpa_supplicant.conf ,这个是系统文件,权限不够高是无法访问的,而这个文 ...