Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Android
- 안드로이드 서비스
- android tutorial
- 개발강의
- android example
- 안드로이드 네비게이션 메뉴
- android studio 앱 만드는 법
- 코틀린
- 개발자
- 홍드로이드 강의
- 자바 튜토리얼
- Android Studio
- 안드로이드 기초
- Android Java
- 안드로이드 코딩 기초
- 안드로이드 앱 만들기
- java
- hongdroid
- 안드로이드 튜토리얼
- 안드로이드
- 플러터
- 자바
- 안드로이드 예제
- IOS
- 코딩
- 앱 만들기
- 앱 만드는 법
- 홍드로이드
- 안드로이드 스튜디오
- flutter
Archives
- Today
- Total
홍드로이드의 야매코딩
#13 안드로이드 스튜디오 프래그먼트 (Fragment) 예제 [ 홍드로이드 ] 본문
[activity_main.xml]
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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"> <FrameLayout android:id="@+id/frame" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentBottom="true"> <Button android:id="@+id/btn_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="메뉴1" /> <Button android:id="@+id/btn_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="메뉴2" /> <Button android:id="@+id/btn_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="메뉴3" /> <Button android:id="@+id/btn_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="메뉴4" /> </LinearLayout> </RelativeLayout> | cs |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | package com.example.fragmentexample; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { Button btn1,btn2,btn3,btn4; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button)findViewById(R.id.btn_1); btn2 = (Button)findViewById(R.id.btn_2); btn3 = (Button)findViewById(R.id.btn_3); btn4 = (Button)findViewById(R.id.btn_4); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); Fragment1 fragment1 = new Fragment1(); transaction.replace(R.id.frame, fragment1); transaction.commit(); } }); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); Fragment2 fragment2 = new Fragment2(); transaction.replace(R.id.frame, fragment2); transaction.commit(); } }); btn3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); Fragment3 fragment3 = new Fragment3(); transaction.replace(R.id.frame, fragment3); transaction.commit(); } }); btn4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); Fragment4 fragment4 = new Fragment4(); transaction.replace(R.id.frame, fragment4); transaction.commit(); } }); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="홍드로이드 천재"/> </FrameLayout> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="홍드로이드 바보"/> </FrameLayout> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="홍드로이드 멋쟁이"/> </FrameLayout> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:text="홍드로이드 귀요미"/> </FrameLayout> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.example.fragmentexample; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Fragment1 extends Fragment { public Fragment1() { } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment1, container, false); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.example.fragmentexample; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Fragment2 extends Fragment { public Fragment2() { } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment2, container, false); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.example.fragmentexample; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Fragment3 extends Fragment { public Fragment3() { } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment3, container, false); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.example.fragmentexample; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Fragment4 extends Fragment { public Fragment4() { } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment4, container, false); } } | cs |
'Android Java' 카테고리의 다른 글
#15 안드로이드 스튜디오 Thread & Handler (스레드 & 핸들러) 예제 [ 홍드로이드 ] (0) | 2019.06.02 |
---|---|
#14 안드로이드 스튜디오 (Log출력 및 주석다는 법) 예제 [ 홍드로이드 ] (2) | 2019.06.02 |
#12 안드로이드 스튜디오 리사이클러뷰 (Recycler View) 예제 [ 홍드로이드 ] (2) | 2019.05.21 |
#11 안드로이드 스튜디오 카메라 (Camera) 예제 [ 홍드로이드 ] (12) | 2019.05.21 |
#10 안드로이드 스튜디오 네비게이션 메뉴 (Navigation Menu Custom) 예제 [ 홍드로이드 ] (2) | 2019.05.21 |
Comments