Android开源项目——设置图文居中的按钮 IconButton
来源:互联网 发布:顾客数据 编辑:程序博客网 时间:2024/06/07 22:20
本文介绍一下一个小众的开源项目——IconButton。
本文原创,转载请注明出处:
http://blog.csdn.net/maosidiaoxian/article/details/43560209
简介
这是一个老外两年前写的项目,见:https://github.com/pnc/IconButton。它可以使一个Button的图片与文字一起居中,如下图:
以前要实现这种效果却是用一个Layout和一个ImageView一个TextView来实现它的同学,看到这个项目的这一刻,满满的感动有木有?
扩展
为方便在项目中使用,及实现项目里的其它需求,我fork了此项目,对它进行了修改和扩展,并发布到jCenter中。另外,表示老外真的很友好。
为实现设计师设计的界面,我对它的扩展如下:
1.扩展了居中策略。原来的IconButton中,是图片、图片与文字的间距和文字一起居中的。我扩展为默认是这三个一起居中,但也可以设置为仅文字居中或者文字与间距居中。
2.增加了IconCheckBox。这主要是为实现下图中的效果:
在上图中,文字是要居中的,而小箭头则在它旁边,并且小箭头与文字有一定的间距。
我的项目地址为:https://github.com/msdx/IconButton。扩展的内容见develop分支。
使用
对于使用Gradle 构建的Android Studio项目,使用方式很简单,先确定你在根项目的build.gradle中声明了JCenter中央仓:
repositories { jcenter()}
然后在模块中的build.gradle中添加此依赖:
dependencies { compile 'com.githang:com-phillipcalvin-iconbutton:2.0.2'}
对于Eclipse项目,且不是用Gradle构建的,那就乖乖地拷贝代码或导入项目吧。
接下来,只要在布局文件中用这个IconButton或IconCheckBox就可以了,代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"<!-- ... --> <com.phillipcalvin.iconbutton.IconButton android:id="@+id/search" android:drawableLeft="@drawable/action_search" android:text="@string/search" app:iconPadding="10dp" />
其中的iconPadding是图片与文字的间距。
其它扩展使用见项目中的app模块的代码。
1 1
- Android开源项目——设置图文居中的按钮 IconButton
- Android开源项目——设置图文居中的按钮 IconButton
- android图文居中按钮控件
- IOS图文按钮居中排列
- Android ImageSpan的图文居中对齐
- 设置按钮居中
- Android中设置半个屏幕大小且居中的按钮布局 (layout_weight属性)
- Android中设置半个屏幕大小且居中的按钮布局 (layout_weight属性)
- 设置按钮上的文字靠左靠右居中显示
- 设置按钮的contentMode, 让其图片居中填充显示
- 图文详解——将github开源项目导入android studio
- Android ImageSpan使TextView的图文居中对齐
- android设置Gallery 居中的一种解决方法
- Android设置Toolbar的标题居中
- Android设置Toolbar的标题居中
- 设置按钮文字居中(alignment属性)
- 设置按钮内容水平居中方式
- Html中设置按钮竖直居中
- 2015美国大学生数学建模竞赛题目及翻译
- IP之IP Packet Format
- 【数据库-MySql】 MySqlConnection error connecting: Timeout expired. (1)
- 去掉VS2012中的红色波浪下划线
- android文档代理网址
- Android开源项目——设置图文居中的按钮 IconButton
- SVM算法入门
- 优化网站加载速度的14个技巧
- ASP.NET服务器端处理手机登陆
- MyEclipse使用教程:MyEclipse的远程调试
- #学习笔记#Concept of Hashing
- java并发库java.util.concurrent各类的使用示例
- springMVC对于controller处理方法返回值的可选类型
- iOS文件,保存路径. 防止加到iCloud备份