Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 實現圖片與文字上下排列的 RadioButton 布局

編輯:關於 Android 程式設計

在 Android 開發中,經常會用到帶文字和圖片的按鈕。下面介紹如何使用 RadioButton 實現圖片和文字的上下布局(或左右布局),代碼非常簡單,就不多做解釋了。

布局文件用來展示 RadioButton 的使用方法:

 <?xml version="." encoding="utf-"?> <RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:button="@null" android:drawableTop="@drawable/ic_launcher" android:text="Test Button" /> </RelativeLayout>

效果圖如下:

這裡的關鍵在於 android:button="@null" 去掉系統默認的單選按鈕,再用 android:drawableTop 把圖片放在文字上方,從而實現圖文上下排列的效果。以上代碼沒有添加注釋,相信大家都能看懂;如有任何問題,歡迎留言交流。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved