static_fragment.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cde"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ข้อความนี้อยู่บน Layout ของ Fragment " android:textSize="20sp" android:layout_gravity="center_horizontal" android:layout_margin="20dp"/> </LinearLayout> |
StaticFragment.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.phaisarn.myapplication; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class StaticFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { View view = inflater.inflate(R.layout.static_fragment, viewGroup, false); return view; } } |
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 |
<?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"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="30dp" android:text="ข้อความนี้อยู่บน Layout ของ Activity" android:textSize="20sp" /> <FrameLayout android:id="@+id/frameLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:id="@+id/fragment" android:name="com.phaisarn.myapplication.StaticFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> </LinearLayout> |