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

Android GridView 不改變背景色實現網格線效果

編輯:關於 Android 開發

Android GridView 不改變背景色實現網格線效果


專案中需要為 GridView 加上網格線,而 GridView 的背景又是一張完整的圖片,如下圖所示:

常見的做法是透過 shape 的 stroke 屬性來畫出格線,而不必更動 GridView 的背景色,核心的 shape 定義如下:

<shape xmlns:android="https://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke
        android:width="1dp"
        android:color="@android:color/darker_gray">
    </stroke>
</shape>

在 Android Studio 的 Preview 中可以很方便地預覽到該效果:

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