티스토리 뷰
activity_main.xml
<?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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btnRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RED"
android:textSize="24dp"
android:onClick="onClick"/>
<Button
android:id="@+id/btnGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GREEN"
android:textSize="24dp"
android:onClick="onClick"/>
<Button
android:id="@+id/btnBlue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BLUE"
android:textSize="24dp"
android:onClick="onClick"/>
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearRed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFBBBB"/>
<LinearLayout
android:id="@+id/linearGreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#BBFFBB"/>
<LinearLayout
android:id="@+id/linearBlue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#BBBBFF"/>
</FrameLayout>
</LinearLayout>
MainActivity.kt
package com.jwsoft.kotlinproject
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.LinearLayout
class MainActivity : AppCompatActivity(), View.OnClickListener {
private lateinit var btnRed: Button
private lateinit var btnGreen: Button
private lateinit var btnBlue: Button
private lateinit var linearRed: LinearLayout
private lateinit var linearGreen: LinearLayout
private lateinit var linearBlue: LinearLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnRed = findViewById(R.id.btnRed)
btnGreen = findViewById(R.id.btnGreen)
btnBlue = findViewById(R.id.btnBlue)
linearRed = findViewById(R.id.linearRed)
linearGreen = findViewById(R.id.linearGreen)
linearBlue = findViewById(R.id.linearBlue)
}
override fun onClick(v: View?) {
linearRed.visibility = View.INVISIBLE
linearGreen.visibility = View.INVISIBLE
linearBlue.visibility = View.INVISIBLE
when (v) {
btnRed -> {
linearRed.visibility = View.VISIBLE
}
btnGreen -> {
linearGreen.visibility = View.VISIBLE
}
btnBlue -> {
linearBlue.visibility = View.VISIBLE
}
}
}
}
'Android > Kotlin' 카테고리의 다른 글
[Kotlin] ViewPager2 + RecyclerView.Adapter (0) | 2020.07.03 |
---|---|
[Kotlin] TabLayout (0) | 2020.07.02 |
[Kotlin] Fragment (0) | 2020.07.01 |
[Kotlin] BottomSheetDialogFragment (0) | 2020.07.01 |
[Kotlin] BottomSheetDialog (0) | 2020.07.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- JSONObject
- Intent
- Vue.js #Vue.js + javascript
- DataBinding
- Livedata
- Architecture Pattern
- Design Pattern
- View
- fragment
- Android
- 안드로이드
- JSONArray
- ArrayList
- CoordinatorLayout
- XML
- MVVM
- 코틀린
- TabLayout
- handler
- 안드로이드 #코틀린 #Android #Kotlin
- coroutine
- ViewModel
- 혀가 길지 않은 개발자
- recyclerview
- ViewPager2
- James Kim
- activity
- Kotlin
- 자바
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함