728x90
activity_main.xml
<?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="match_parent"
tools:context=".MainActivity">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="162dp"
android:layout_height="109dp"
android:layout_marginStart="25dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="누가(7.0)" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="오레오(8.0)" />
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="파이(9.0)" />
</RadioGroup>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="26dp"
android:layout_marginTop="59dp"
android:text="좋아하는 안드로이드 버전은?"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="46dp"
android:text="선택을 시작하겠습니까?"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/switch1"
app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="29dp"
android:layout_marginTop="16dp"
android:text="시작함"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<ImageView
android:id="@+id/nuga"
android:layout_width="71dp"
android:layout_height="73dp"
android:layout_marginStart="24dp"
android:layout_marginTop="22dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
app:srcCompat="@drawable/img1" />
<ImageView
android:id="@+id/pie"
android:layout_width="101dp"
android:layout_height="69dp"
android:layout_marginStart="18dp"
android:layout_marginTop="22dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
app:srcCompat="@drawable/img3" />
<ImageView
android:id="@+id/oreo"
android:layout_width="70dp"
android:layout_height="126dp"
android:layout_marginStart="18dp"
android:layout_marginTop="13dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup"
app:srcCompat="@drawable/img2" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="31dp"
android:layout_marginTop="34dp"
android:text="종료"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/oreo" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="31dp"
android:layout_marginTop="14dp"
android:text="처음으로"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.example.project22
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Switch
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setTitle("안드로이드 사진 보기")
textView.setVisibility(android.view.View.INVISIBLE)
radioGroup.setVisibility(android.view.View.INVISIBLE)
nuga.setVisibility(android.view.View.INVISIBLE)
pie.setVisibility(android.view.View.INVISIBLE)
oreo.setVisibility(android.view.View.INVISIBLE)
button.setVisibility(android.view.View.INVISIBLE)
button2.setVisibility(android.view.View.INVISIBLE)
switch1.setOnCheckedChangeListener { buttonView, isChecked ->
if(isChecked){
textView.setVisibility(android.view.View.VISIBLE)
radioGroup.setVisibility(android.view.View.VISIBLE)
button.setVisibility(android.view.View.VISIBLE)
button2.setVisibility(android.view.View.VISIBLE)
if(radioButton1.isChecked ){
nuga.setVisibility(android.view.View.VISIBLE)
pie.setVisibility(android.view.View.INVISIBLE)
oreo.setVisibility(android.view.View.INVISIBLE)
}else if(radioButton2.isChecked){
nuga.setVisibility(android.view.View.INVISIBLE)
pie.setVisibility(android.view.View.INVISIBLE)
oreo.setVisibility(android.view.View.VISIBLE)
}else{
nuga.setVisibility(android.view.View.INVISIBLE)
pie.setVisibility(android.view.View.VISIBLE)
oreo.setVisibility(android.view.View.INVISIBLE)
}
}
else {
textView.setVisibility(android.view.View.INVISIBLE)
radioGroup.setVisibility(android.view.View.INVISIBLE)
nuga.setVisibility(android.view.View.INVISIBLE)
pie.setVisibility(android.view.View.INVISIBLE)
oreo.setVisibility(android.view.View.INVISIBLE)
button.setVisibility(android.view.View.INVISIBLE)
button2.setVisibility(android.view.View.INVISIBLE)
}
}
radioGroup.setOnCheckedChangeListener { group, checkedId ->
if(radioButton1.isPressed){
nuga.setVisibility(android.view.View.VISIBLE)
pie.setVisibility(android.view.View.INVISIBLE)
oreo.setVisibility(android.view.View.INVISIBLE)
}else if(radioButton2.isPressed){
nuga.setVisibility(android.view.View.INVISIBLE)
pie.setVisibility(android.view.View.INVISIBLE)
oreo.setVisibility(android.view.View.VISIBLE)
}else{
nuga.setVisibility(android.view.View.INVISIBLE)
pie.setVisibility(android.view.View.VISIBLE)
oreo.setVisibility(android.view.View.INVISIBLE)
}
}
button.setOnClickListener {
System.exit(0)
}
button2.setOnClickListener {
radioButton2.setChecked(true)
switch1.setChecked(false)
}
}
}
실행 결과
728x90