Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發實例

Android 圖片覆蓋實作:用重疊 ImageView 打造遮罩效果

編輯:Android 開發實例

想讓一張圖片疊在 Gallery 之上做出遮罩或邊框效果嗎?只要善用 RelativeLayout 的對齊屬性,讓 ImageView 覆蓋在 Gallery 上即可。以下是版面配置:

<RelativeLayout
xmlns:android="https://schemas.android.com/apk/res/android"
android:id="@+id/gallerylayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery
android:id="@+id/overview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/navigmaske"
android:background="#0000"
android:src="@drawable/a2"
android:scaleType="fitXY"
android:layout_alignTop="@id/overview"
android:layout_alignBottom="@id/overview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>

關鍵在於兩個屬性:android:background="#0000" 將背景設為全透明,而 android:src="@drawable/a2" 指向的圖片要是 PNG 透明素材。透過 layout_alignTop 與 layout_alignBottom 讓 ImageView 上下都對齊 Gallery,就能完美覆蓋在其上,實現遮罩或裝飾效果。

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