w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Android: adding fragment to WindowManager

Add a container layout to you main layout(ActivityLayout) in a way that this layout always be on top and add you fragment in that layout. That's it.

Have a look at following Xml layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
    android:id="@+id/frameBottomContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#bbbbbb" >
</FrameLayout>

<FrameLayout
    android:id="@+id/frameTopContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/frameBottomContainer"
    android:layout_gravity="start"
    android:background="#cccccc" >
</FrameLayout>

<FrameLayout
    android:id="@+id/frameExtraViewTopContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start">
</FrameLayout><!-- this is the container that will always be on
top-->

</com.bbi.views.FractionRelativeLayout>

Now you can add fragment like following:

getActivity().getFragmentManager().beginTransaction().add(R.id.frameExtraViewTopContainer,fragment).commitAllowingStateLoss();




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.