Kotlin -1

2022. 3. 30. 10:31IT/안드로이드

반응형

지금 학습하고 있는것은 Android 공식 문서로 공부중이다. 

https://developer.android.com/codelabs/kotlin-android-training-app-anatomy?hl=ko#0 

 

Android Kotlin Fundamentals 01.2: Anatomy of Basic Android Project  |  Android Developers

Learn your way around the files that make up an Android project, and create an app with an interactive button.

developer.android.com

 

안드로이드 스튜디오부터 설치하고, 차근차근 따라가는 중인데 ...

맨날 리눅스로 개발하다가 개발 UI툴 쓸라니까 여간 어색한게 아니구만..

근데 쓰면서 적응되면 훨씬 간편하고 좋을것 같다. 

지금 커리큘럼을 보니,  Empty project 만들어서 소스코드 조금씩 수정하는 식으로 layout 을 파악하는 것 같다. 

레이아웃은 다음과 같다. 

main 디렉토리 아래로 java 와 res 가 있다. 

여기서 초점을 맞춰야할 파일이 2가지 있는데, MainActivity와 activity_main.xml 이다. 

Activity 는 안드로이드에서 제일 중요한 것으로, 

만약 App을 launching 하면 제일 처음 불러오는 파일이 AndroidManifest.xml 파일이다. 여기서 MainActivity 를 불러와 사용하는걸로 파악됨.

여기서 res/layout 이 View단이다. 

View 는 ... text, button, image, checkbox 단 등등을 말한다.

res/layout에서, activity_main.xml 을보면, <LinearLayout> 이 있다.

<?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="wrap_content"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

</LinearLayout>

요게 ViewGroup인데, 스크린에 직접적으로 표시되는 position을 말한다. 

소스코드에서는 좀 달랐는데, 메뉴얼을 보니.... 

Default Root 의 new android project 에서는 ConstraintLayout 이라고 표시될텐데, 이건 design editor 에서 작업이 용이하고.. LinearLayout view group이 더 심플하다고함. ! 

그래서 기존 소스는 원래 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Hello World!"
        tools:ignore="MissingConstraints" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Roll"
        tools:ignore="MissingConstraints" />


</androidx.constraintlayout.widget.ConstraintLayout>

요거였는데, 

androidx.constraintlayout.widget.ConstraintLayout

이걸 LinearLayout으로 바꿔주었더니, 글자와 버튼의 중첩 현상이 해결되었다. ! 

 

 

 

728x90
반응형