如何在 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>

在上述代码中,我们添加了 image view 并在其中添加了 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="426.667"
   android:viewportHeight="426.667">
   <path
      android:fillColor="#6AC259"
      android:pathData="M213.333,0C95.518,0 0,95.514 0,213.333s95.518,213.333 213.333,
                        213.333c117.828,0 213.333,-95.514 213.333,-213.333S331.157,
                        0213.333,0zM174.199,322.918l-93.935,-93.931l31.309,-31.309l62.626,
                        62.622l140.894,-140.898l31.309,31.309L174.199,322.918z" />
</vector>

尝试运行你的应用程序。我假设你已将真实的 Android 移动设备连接到了计算机。要从 Android Studio 运行该应用程序,打开其中一个项目的活动文件,然后单击工具栏中运行  图标。选择你的移动设备作为选项,然后查看你的移动设备,它将显示你的默认屏幕 -

单击 此处 下载项目代码

更新于: 2020 年 6 月 27 日

907 浏览量

开启您的 职业

完成本课程并获得认证

开始
广告
© . All rights reserved.