如何在 Android 中繪製個人資料圖示形狀?


此示例演示如何在 Android 中繪製個人資料圖示形狀。

步驟 1 − 在 Android Studio 中建立一個新專案,選擇檔案 ⇒ 新建專案並填寫所有所需資訊以建立一個新專案。

步驟 2 − 新增以下程式碼到 res/layout/activity_main.xml。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:gravity="center"
   android:layout_marginTop="30dp"
   tools:context=".MainActivity">
   <ImageView
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@drawable/background"/>
</LinearLayout>

在上面的程式碼中,我們已經採用 imageview 並將背景新增為 background.xml。

步驟 3 − 新增以下程式碼到 drawable/background.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
   android:width="24dp"
   android:height="24dp"
   android:autoMirrored="true"
   android:viewportWidth="277.58"
   android:viewportHeight="277.58">
   <path
      android:fillColor="#D80027"
      android:pathData="M138.46,164.287c-38.628,0 -69.925,-37.519 -69.925,-83.767C68.535,
                        34.277 99.832,0 138.46,0c38.634,0 69.957,34.277 69.957,80.52C208.417,
                        126.768 177.093,164.287 138.46,164.287zM29.689,277.528c0,0 -14.832,
                        0.979 -21.365,-8.023c-3.53,-4.863 -1.071,-14.718 1.343,-20.217l5.912,
                        -13.473c0,0 16.35,-36.567 34.962,-57.757c11.433,-12.994 25.031,
                        -10.035 33.826,-5.809c5.417,2.6 11.542,10.176 16.018,14.191c6.168,
                        5.532 17.057,11.819 34.859,12.173h10.922c17.791,-0.354 28.68,
                        -6.641 34.843,-12.173c4.471,-4.014 10.427,-11.825 15.795,
                        -14.511c8.072,-4.041 20.358,-6.527 31.492,6.13c18.618,21.191 33.363,
                        58.421 33.363,58.421l6.059,13.212c2.507,5.461 5.075,15.267 1.643,
                        20.195c-6.124,8.811 -19.874,7.642 -19.874,7.642S29.689,277.528 29.689,
                        277.528z" />
</vector>

讓我們嘗試執行你的應用程式。我假設你已將安卓移動裝置與計算機相連。透過 Android Studio 執行應用程式,開啟專案的活動檔案之一併單擊工具欄中的執行  圖示。選擇你的移動裝置為選項,然後檢查你的移動裝置,它將顯示你的預設螢幕,

點選 這裡 下載專案程式碼

更新於: 2020 年 6 月 27 日

620 次瀏覽

為你的職業生涯奠定基礎

完成課程可獲得認證

開始
廣告
© . All rights reserved.