본문 바로가기
App Programming/Kotlin

[Kotlin] UI 프로그래밍 (2)

by goatlab 2023. 1. 12.
728x90
반응형
SMALL

id 속성

 

id는 Layout XML에 등록되는 View 객체 식별자이다.

 

<TextView
	android:id="@+id/text1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="텍스트1"/>

 

그 다음 findViewById( ) 함수로 View 객체 획득한다.

 

val textView1: TextView = findViewById(R.id.text1)

 

layout_width / layout_height

 

View 사이즈를 지정하며 필수 속성이다.

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button1"
            android:backgroundTint="#ff0000"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button2"
            android:backgroundTint="#00ff00"/>
        <Button
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:text="Button3"
            android:backgroundTint="#0000ff"/>
    </LinearLayout>

 

margin / padding

 

margin은 View와 View 사이의 간격, padding은 View의 컨텐츠와 View 테두리 사이의 간격이다. padding, margin 속성을 이용하면 네 방향 모두 동일한 사이즈로 간격 설정할 수 있다. 한 방향의 간격만 설정하고 싶다면 paddingLeft, paddingRight, paddingTop, paddingBottom와 layout_marginLeft, layout_marginRight, layout_marginTop, layout_marginBottom 속성을 이용한다.

 

visibility

 

 

visibility 속성은 View가 화면에 출력되어야 하는지에 대한 설정한다. visible(default), invisible, gone 값으로 설정한다. invisible과 gone은 모두 화면에 View가 보이지 않게 하지만 사이즈를 확보하는지에 대한 차이가 있다.

728x90
반응형
LIST

'App Programming > Kotlin' 카테고리의 다른 글

[Kotlin] ImageView  (0) 2023.01.12
[Kotlin] TextView  (0) 2023.01.12
[Kotlin] UI 프로그래밍 (1)  (0) 2023.01.12
[Kotlin] Camera  (0) 2023.01.11
[Kotlin] Jetpack BottomNavigationView  (0) 2023.01.09