Android Jetpack | ||||||||||
| ||||||||||
| ||||||||||
| ||||||||||
| ||||||||||
|
Fragment, Android Jetpack UI Components, A basic unit of composable UI
Android introduced fragments in Android 3.0 (API level 11), A Fragment is a behavior or a portion of user interface in a FragmentActivity. A FragmentActivity shall contain one or more reusable fragments.
Fragment will have its own life cycle, and directly affected by the host activity's lifecycle.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.freedomtutorials.MyFragment"
android:id="@+id/list"
android:layout_weight="2"
android:layout_width="2dp"
android:layout_height="match_parent" />
</LinearLayout>
Fragments will has its own class to implement, and in the <fragment> definition of parent activity layout xml file, the android:name attribute specifies the Fragment class to instantiate.
//get the instance of FragmentManager, Method of FragmentActivity subclass
FragmentManager objFragmentManager = getSupportFragmentManager();
//begin fragment transaction
FragmentTransaction objFragmentTransaction = objFragmentManager.beginTransaction();
//create instance of your Fragment implementation
MyFragment objMyfragment = new MyFragment();
//add it to fragment transaction
objFragmentTransaction.add(R.id.my_fragment_layout_container, objMyfragment);
//commit
objFragmentTransaction.commit();
MyFragment objMyfragment = (MyFragment) getSupportFragmentManager().findFragmentById(R.id.my_fragment_layout_container);
Animation & transitions, Android Jetpack UI Components, Move widgets and transition between screens
posted on 2019-10-25 08:04:17 - Android Jetpack Tutorials
Emoji, Android Jetpack UI Components, Enable an up-to-date emoji font on older platforms
posted on 2019-10-25 08:03:43 - Android Jetpack Tutorials
Fragment, Android Jetpack UI Components, A basic unit of composable UI
posted on 2019-10-25 08:03:24 - Android Jetpack Tutorials