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

Android TextView 與 ImageView 基礎用法說明

編輯:關於 Android 程式設計

TextView 有個很方便的屬性,可以直接在文字的四個方位擺放小圖示,省去額外排版 RelativeLayout 的麻煩。看下面這個簡單的版面:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:drawableLeft="@drawable/icon"
        android:text="@string/app_name"
        />

</LinearLayout>

看到 android:drawableLeft 這個屬性,應該就明白它的用途了:

android:drawableLeft=""
android:drawableRight=""
android:drawableTop=""
android:drawableBottom=""

這四個屬性分別對應文字的左、右、上、下四個方向,可以放不同的圖示。搭配 android:drawablePadding 還能設定圖示與文字之間的間距,非常實用——不必再像以前那樣靠 RelativeLayout 去微調 left 或 right 的對齊了。

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