greenhelix
greenhelix
greenhelix
07-16 17:57
  • All (229)
    • Algorithm (118)
      • Algorithm (17)
      • Graph (0)
      • Core (6)
      • Python (18)
      • PythonSnippet (4)
      • Java (59)
      • Kotlin (14)
    • Project (0)
    • Study (8)
      • License (5)
      • EIP (3)
    • Programming (63)
      • Android (41)
      • Flutter (1)
      • Bugs Life (21)
      • Linux (0)
    • Tech (32)
      • Tech (17)
      • Drone (4)
      • Hacking (11)
    • Life (6)
      • INGRESS (1)
      • 심시티빌드잇 (0)
250x250

티스토리

hELLO · Designed By 정상우.
greenhelix

greenhelix

View Hierarchy 뷰 계층 구조
Programming/Android

View Hierarchy 뷰 계층 구조

2021. 7. 12. 19:47

View Hierarchy 

뷰의 계층구조

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="@string/question_text"
        />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:text="@string/true_button"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button"
            />
            
    </LinearLayout>
    
</LinearLayout>

위의 코드는 아래의 표처럼 계층을 가진 상태로 구성된다. 

view에 해당하는 모든 xml 코드들은 이런 식으로 구성되어있다. 

 

LinearLayout
TextView LinearLayout
  Button Button

최고 상단 루트(뿌리에)에 속하는 요소는 LinearLayout이다. 

이 것에는 안드로이드 리소스 xml 네임스페이스를 지정해줘야한다. 

그 코드가 바로 익숙한 아래의 코드이다. 

xmls:android="http://schemeas.android.com/apk/res/android"

 

ViewGroup 에는 Linear, Constraint, Frame 등 다양한 서브클래스가 있다. 

ViewGroup에 포함되는 모든 View들은 뷰그룹의 자식(Child)라 부른다.

Linearlayout의 자식은 Textview, Linearlayout이며, 

두번째 linearlayout의 자식은 2개의 Button 이다. 

 

 

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'Programming > Android' 카테고리의 다른 글

Resource 리소스  (0) 2021.07.12
All Of Android Setting  (0) 2021.07.12
안드로이드 버전 정보  (0) 2021.07.08
    'Programming/Android' 카테고리의 다른 글
    • Class
    • Resource 리소스
    • All Of Android Setting
    • 안드로이드 버전 정보
    greenhelix
    greenhelix
    개발에 관한 것들과 개인적인 것을 담는 블로그

    티스토리툴바