[안드로이드] 이미지 불러오기

반응형
반응형

이미지 불러오기

 

목차

     

     

      이미지 불러오기

    res > drawable

    이미지는 보통 res > drawable 안에 집어넣는다.

     

    이미지를 넣을 경우 생기는 팝업

    이미지를 넣고 싶다면, 이미지를 드레그 하여 drawable 안에 넣는다.

    성공적으로 옮겼다면 위와 같이 팝업창이 발생하게 되는데, Refactor을 클릭하면 된다.

     

    제대로 집어 넣었다면, 위와 같이 이미지가 들어간 모습을 확인 할 수 있다.

    이렇게 저장하고 싶은 사진을 넣었다면 끝났다.

     

    이미지 가져오기

        <ImageView
            android:src="@drawable/mollang1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            />

    html과 css와 비슷한 점이 있다.

    src는 이미지의 위치를 파악하며,

    layout_width와 layout_height는 이미지의 크기를 나타낸다.

     

    똑같은 코드를 3번 나열했더니, 3개의 사진이 나열되었다.

     

     

    위의 사진처럼 나열된 이유는 LinearLayout를 적용시켰기 때문이다.

     

     

      LinearLayout 추가하기

    LinearLayout 추가하기

    LinearLayout안에 다시 한 번 LinearLayout을 추가하였다.

    LinearLayout은 빈 공간에 넣는 특성을 지닌 Layout이다.

     

    새로추가한 LinearLayout에 match_parent의 특성을 추가한다.

     

    가로가 꽉찼으므로, 아래로 밀려난다.

    가로로 나열되던 LinearLayout이 새로로 나열되기 시작한다.

     

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical">
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="120dp">
    
            <ImageView
                android:src="@drawable/mollang1"
                android:layout_width="100dp"
                android:layout_height="100dp"
                />
    
            <ImageView
                android:src="@drawable/mollang2"
                android:layout_width="100dp"
                android:layout_height="100dp"
                />
    
            <ImageView
                android:src="@drawable/mollang3"
                android:layout_width="100dp"
                android:layout_height="100dp"
                />
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="120dp">
    
            <ImageView
                android:src="@drawable/mollang4"
                android:layout_width="100dp"
                android:layout_height="100dp"
                />
    
            <ImageView
                android:src="@drawable/mollang5"
                android:layout_width="100dp"
                android:layout_height="100dp"
                />
    
            <ImageView
                android:src="@drawable/mollang6"
                android:layout_width="100dp"
                android:layout_height="100dp"
                />
    
        </LinearLayout>
    
    </LinearLayout>

    사진은  drawable 디렉토리 안의 mollang이라는 이름을 사진들을 불러왔다.

     

     

      마무리

    안드로이드의 시작.

    처음부터 한 발자국씩

    반응형

    댓글

    Designed by JB FACTORY