티스토리 뷰
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">
<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: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.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private LinearLayout linearRed;
private LinearLayout linearGreen;
private LinearLayout linearBlue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearRed = findViewById(R.id.linearRed);
linearGreen = findViewById(R.id.linearGreen);
linearBlue = findViewById(R.id.linearBlue);
}
@Override
public void onClick(View v) {
linearRed.setVisibility(View.INVISIBLE);
linearGreen.setVisibility(View.INVISIBLE);
linearBlue.setVisibility(View.INVISIBLE);
switch (v.getId()) {
case R.id.btnRed:
linearRed.setVisibility(View.VISIBLE);
break;
case R.id.btnGreen:
linearGreen.setVisibility(View.VISIBLE);
break;
case R.id.btnBlue:
linearBlue.setVisibility(View.VISIBLE);
break;
}
}
}
'Android > Java' 카테고리의 다른 글
[Java] CoordinatorLayout + AppBarLayout + Toolbar + RecyclerView (0) | 2020.07.03 |
---|---|
[Java] TabLayout (0) | 2020.07.03 |
[Java] Fragment (0) | 2020.07.02 |
[Java] BottomSheetDialogFragment (0) | 2020.07.01 |
[Java] BottomSheetDialog (0) | 2020.07.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- recyclerview
- java
- Intent
- ViewModel
- 혀가 길지 않은 개발자
- TabLayout
- MVVM
- DataBinding
- CoordinatorLayout
- 자바
- handler
- Kotlin
- Architecture Pattern
- Livedata
- ViewPager2
- 코틀린
- coroutine
- JSONObject
- James Kim
- Design Pattern
- XML
- ArrayList
- fragment
- activity
- 안드로이드
- 안드로이드 #코틀린 #Android #Kotlin
- JSONArray
- Android
- View
- Vue.js #Vue.js + javascript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함