Computer >> 컴퓨터 >  >> 프로그램 작성 >> Android

안드로이드에서 가까운 모양을 그리는 방법?

<시간/>

이 예제는 Android에서 가까운 모양을 그리는 방법을 보여줍니다.

1단계 − Android Studio에서 새 프로젝트를 생성하고 파일 ⇒ 새 프로젝트로 이동하여 필요한 모든 세부 정보를 입력하여 새 프로젝트를 생성합니다.

2단계 − res/layout/activity_main.xml에 다음 코드를 추가합니다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
   xmlns:tools="https://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="https://schemas.android.com/apk/res/android"
   android:width="24dp"
   android:height="24dp"
   android:autoMirrored="true"
   android:viewportWidth="612"
   android:viewportHeight="612">
   <path
      android:fillColor="#FF000000"
      android:pathData="M612,306C612,137.004 474.995,0 306,0C137.004,0 0,137.004 0,
                        306c0,168.995 137.004,306 306,306C474.995,612 612,474.995 612,
                        306zM168.3,424.032L286.333,306L168.3,187.967l19.667,-19.667L306,
                        286.333L424.032,168.3l19.668,19.667L325.667,306L443.7,424.032L424.032,
                        443.7L306,325.667L187.967,443.7L168.3,424.032z" />
</vector>

응용 프로그램을 실행해 보겠습니다. 실제 Android 모바일 장치를 컴퓨터에 연결했다고 가정합니다. Android 스튜디오에서 앱을 실행하려면 프로젝트의 활동 파일 중 하나를 열고 도구 모음에서 실행 아이콘을 클릭합니다. 모바일 장치를 옵션으로 선택한 다음 기본 화면을 표시할 모바일 장치를 확인하십시오 –

안드로이드에서 가까운 모양을 그리는 방법?