Fragment demo
left fragment:
package com.easymorse.demos;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class DemoLeftFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.demo_left_fragment, container,false);
}
}
demo_left_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="demo left fragment" />
Right fragment:
package com.easymorse.demos;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class DemoRightFramgment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.demo_right_fragment, container,false);
}
}
demo_right_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="demo right fragment" />
Activity:
package com.easymorse.demos;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
public class FragmentDemoActivity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//START.for first main.xml
FragmentManager fragmentManager=getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
DemoLeftFragment leftFragment=new DemoLeftFragment();
DemoRightFramgment rightFramgment=new DemoRightFramgment();
fragmentTransaction.add(R.id.leftView, leftFragment);
fragmentTransaction.add(R.id.rightView, rightFramgment);
fragmentTransaction.commit();
// END. }
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/rootView">
<LinearLayout android:id="@+id/leftView"
android:orientation="vertical" android:layout_width="0dp"
android:layout_weight="1" android:layout_height="fill_parent"
android:background="#c0c0c0c0"/>
<LinearLayout android:id="@+id/rightView"
android:orientation="vertical" android:layout_width="0dp"
android:layout_weight="2" android:layout_height="fill_parent" />
</LinearLayout>
or main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/rootView">
<fragment class= "com.easymorse.demos.DemoLeftFragment" android:id="@+id/leftView"
android:orientation="vertical" android:layout_width="0dp"
android:layout_weight="1" android:layout_height="fill_parent"
android:background="#c0c0c0c0"/>
<fragment class="com.easymorse.demos.DemoRightFragment" android:id="@+id/rightView"
android:orientation="vertical" android:layout_width="0dp"
android:layout_height="fill_parent" android:layout_weight="1"/>
</LinearLayout>
相關文章
- FragmentFragment
- Android_Fragment_Fragment詳解AndroidFragment
- Fragment建立Fragment
- Fragment 知識梳理(1) Fragment 原始碼解析Fragment原始碼
- 【BUG系列】Fragment中巢狀Fragment,不顯示Fragment巢狀
- Fragment初學5——使用Fragment的子類PreferenceFragmentFragment
- Fragment詳解Fragment
- Fragment隨筆Fragment
- fragment雜談Fragment
- Android--單Activity+多Fragment,玩轉FragmentAndroidFragment
- Fragment-踩坑Fragment
- Fragment生命週期Fragment
- fragment小認識Fragment
- Fragment的總結Fragment
- Android之FragmentAndroidFragment
- 安卓關閉fragment安卓Fragment
- Activity、Fragment和IntentFragmentIntent
- Fragment流程淺析Fragment
- 動態建立FragmentFragment
- 理解 Android FragmentAndroidFragment
- Fragment 原始碼解析Fragment原始碼
- oracle fragment conceptOracleFragment
- 使用fragment載入自定義fragment出現error inflating class fragment錯誤解決辦法FragmentError
- Fragment 知識梳理(2) Fragment 狀態儲存和恢復Fragment
- Android中Fragment巢狀Fragment,切換Fragment時不顯示檢視的原因及解決方法AndroidFragment巢狀
- fragment返回鍵關閉fragment以及最後一個fragment的時候關閉activity的簡便方法Fragment
- Android基礎—FragmentAndroidFragment
- 巧用Fragment解耦onActivityResultFragment解耦
- Fragment傳值到ActivityFragment
- 重寫返回鍵(Fragment)Fragment
- Fragment的生命週期Fragment
- fragment中listview的onitemclicklistenerFragmentView
- 監聽activity、fragment生命Fragment
- Android Fragment 深度解析AndroidFragment
- Fragment與Activity通訊Fragment
- 在Fragment裡使用viewpagerFragmentViewpager
- Fragment翻蓋動效Fragment
- demo