Android開源項目——設定圖文置中的按鈕 IconButton

來源:互聯網
上載者:User

標籤:iconbutton   圖文置中的按鈕   圖文置中的button   

本文介紹一下一個小眾的開源項目——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模組的代碼。

Android開源項目——設定圖文置中的按鈕 IconButton

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.