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="512"
   android:viewportHeight="512">
   <path
      android:fillColor="#D80027"
      android:pathData="M512,198.525l-176.891,-25.704L256,12.53l-79.108,160.291L0,
                        198.525l128,124.769L97.784,499.47L256,416.291l158.217,
                        83.179l-30.219,-176.176L512,198.525zM256,376.749l-111.731,
                        58.74l21.338,-124.415l-90.393,-88.111l124.92,-18.152L256,
                        91.613l55.867,113.198l124.918,18.152l-90.395,88.111l21.34,
                        124.415L256,376.749z" />
</vector>

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

안드로이드에서 별 ​​모양을 그리는 방법?