转载请注明出处: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. gcc中__attribute__ ((constructor(101)))做成.a库成功链接

    1.cpp:------------------------------------------------ #include int test() __attribute__ ((construct ...

  2. SMART rule之个人理解

    SMART原则通常应用于绩效评估中. S是specific的缩写,也就是你所设定的目标必须是一个具体的目标,而不是一个空而大的东西. 比如你的目标定位为今年学习linux,并对进程管理.内存管理等要能 ...

  3. java.text.MessageFormat格式化字符串时的小技巧

    java.text.MessageFormat格式化字符串时的小技巧 public static void main(String[] args) throws InterruptedExceptio ...

  4. UVa 11371 - Number Theory for Newbies

    題目:給你一個數字n.將裡面每位的數又一次組合形成a,b.使得a-b最大且是9的倍數. 分析:數論. 題目要求a,b和n的位數同样,不能有前導0. 定理1:交換一個數字中的某兩個位的數,形成的新數組和 ...

  5. 设计模式 - 装饰者模式(Decorator Pattern) Java的IO类 用法

    装饰者模式(Decorator Pattern) Java的IO类 用法 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26716 ...

  6. ubuntu下海信Hisense E920 usb连接不上的处理与adb的连接

    解决lssub未能发现海信Hisense USB设置:选择 天翼宽带连接 如下所示: luogw@luogw-ThinkPad-Edge:~$ lsusb Bus 001 Device 002: ID ...

  7. Android开发技术周报

    Android开发技术周报 原文  http://androidweekly.cn/android-dev-weekly-issue48/ 教程 深入理解Android之Gradle Gradle是当 ...

  8. Embedded Linux Primer----嵌入式Linux基础教程--前言

    APractical,Real-WorldApproach ChristopherHallinan 计算机无处不在. 事实上,当然了,对于那些大约在过去25年期间没有生活在洞穴中的人来说没有什么惊奇的 ...

  9. Java---25---集合框架共性方法

    集合类 为什么会出现集合类 面向对象语言对事物的体现都是以对象的形式,所以为了方便对较多个对象的操作,就对对象进行存储,集合就是存储对象最经常使用的一种方式 数组和集合类同一时候容器,有何不同? 数组 ...

  10. Cocos2dx 3.x创建Layer的步骤

    创建 1.新建类文件.注意文件夹为Classes下.否则文件不能正常找到. 2.改动预编译头.如用VS,默觉得#pragma once,为了兼容,改为#ifndef | #define | #endi ...