如何在 Android 中绘制个人资料图标形状?

androidmobile developmentapps/applications

本示例演示了如何在 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 移动设备连接到电脑。要从 Android Studio 运行该应用程序,请打开项目的某个活动文件,然后点击工具栏上的"运行"图标 。选择您的移动设备作为选项,然后勾选将显示默认屏幕的移动设备 –

点击此处下载项目代码


相关文章