Error in inflating map fragment - java

I have a navigation bar and I am working with fragment, menu1fragment is a map, when I tried to use addtobackstack to save my data I have a problem in inflating any solution
MainActivity
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new menu1_fragment();
title = getString(R.string.title_section1);
break;
case 1:
fragment = new menu2_fragment();
title = getString(R.string.title_section2);
break;
case 2:
fragment = new menu4_myfleet();
title = getString(R.string.title_section3);
break;
case 3:
fragment = new menufragment_contact();
title = getString(R.string.title_section4);
break;
case 4:
fragment = new menu5_Emergency();
title = getString(R.string.title_section5);
break;
case 5:
logoutUser();
break;
default:
break;
}
if (fragment != null) {
String backStateName = fragment.getClass().getName();
FragmentManager fragmentManager = getSupportFragmentManager();
boolean fragmentPopped = fragmentManager.popBackStackImmediate(backStateName, 0);
if (!fragmentPopped){ //fragment not in back stack, create it.
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.addToBackStack(backStateName);
fragmentTransaction.commit();
}
/* FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();*/
// set the toolbar title
getSupportActionBar().setTitle(title);
}
}
This is menu1_fragment that inflate the map:
rootview = inflater.inflate(R.layout.activity_map,container,false);
/*get map fragment and puts it in the container */
FragmentManager fm = getChildFragmentManager();
Fragment mapFragment = fm.findFragmentById(R.id.map);
if (mapFragment == null) {
mapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.container_body, mapFragment, "myMap")
.commitAllowingStateLoss();
}
//create the fragment that contain your vehicle
mFragment4Container = (FrameLayout) rootview.findViewById(R.id.fragment4Container);
mFragment4Container.setVisibility(View.GONE);
android.support.v4.app.FragmentTransaction trans = getActivity().getSupportFragmentManager().beginTransaction();
trans.add(mFragment4Container.getId(), new menu3_fragment());
trans.commit();
//create a fragmen for marker profile
mFragment4Containeruser = (FrameLayout) rootview.findViewById(R.id.fragment4Containeruser);
mFragment4Containeruser.setVisibility(View.GONE);
android.support.v4.app.FragmentTransaction transprofile = getActivity().getSupportFragmentManager().beginTransaction();
transprofile.add(mFragment4Containeruser.getId(), new user_info());
transprofile.commit();
This is the error that appears:
android.view.InflateException:Binary XML file line #7: Error inflating class fragment at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719) at
android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at
android.view.LayoutInflater.inflate(LayoutInflater.java:498) at
android.view.LayoutInflater.inflate(LayoutInflater.java:398) at
com.example.fcb.insurance.menu1_fragment.onCreateView(menu1_fragment.java:120)
Menu1_fragment `
<fragment 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:id="#+id/map"
tools:context="com.example.fcb.insurance.map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<FrameLayout
android:id="#+id/fragment4Container"
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#E2E2E2"
android:layout_gravity="bottom"
/>
<FrameLayout
android:id="#+id/fragment4Containeruser"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#E2E2E2"
android:layout_gravity="bottom"
/>
<com.rey.material.widget.Button
style="#style/Material.Drawable.Ripple.Wave.Light"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:text="call expert"
android:id="#+id/buttonclose"
android:layout_marginBottom="100dp"
android:layout_gravity="center_horizontal|bottom"
app:rd_enable="true"/>
<com.rey.material.widget.Button
style="#style/Material.Drawable.Ripple.Wave.Light"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:text="call Tow Truck"
android:id="#+id/button_towtruck"
android:layout_marginBottom="50dp"
android:layout_gravity="center_horizontal|bottom"
app:rd_enable="true"/>
</FrameLayout>
`
Main Activity.xml
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fcb.insurance.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.example.fcb.insurance.FragmentDrawer"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer"
/>
</android.support.v4.widget.DrawerLayout>

Since you are adding the SupportMapFragment using XML in the Menu1_fragment.xml like that
android:name="com.google.android.gms.maps.SupportMapFragment"
then you should remove this code from Menu1_fragment.java
if (mapFragment == null) {
mapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.container_body, mapFragment, "myMap")
.commitAllowingStateLoss();
}
or vice versa.
Edit #1
I also noticed that you are inflating another layout for your menu1_fragment
rootview = inflater.inflate(R.layout.activity_map,container,false);
It should be R.layout.Menu1_fragment instead if R.layout.activity_map

remove android:name from xml declaration, and replace it with:
class="com.google.android.gms.maps.MapFragment"

Related

Fragments are not getting replaced in the main_activity()

I am trying to make navigation drawer using fragments using the reference link : https://guides.codepath.com/android/Fragment-Navigation-Drawer
But the problem is when i tap on any of the item in navigation drawer it does not replace the corresponding fragment to the main activity layout.
Main activity snippet:
public void selectDrawerItem(MenuItem menuItem) {
// Create a new fragment and specify the fragment to show based on nav item clicked
Fragment fragment = null;
Class fragmentClass;
switch(menuItem.getItemId()) {
case R.id.nav_first_fragment:
//fragmentClass = FirstFragment.class;
fragment=new FirstFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.flContent, fragment).commit();
break;
case R.id.nav_second_fragment:
//fragmentClass = SecondFragment.class;
fragment=new SecondFragment();
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.flContent, Fragment.instantiate(MainActivity.this, "com.example.FirstFragment"));
tx.commit();
break;
default:
fragmentClass = FirstFragment.class;
}
activity_main layout:
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<LinearLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
/>
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="#+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:headerLayout="#layout/nav_header"
android:layout_gravity="start"
android:background="#android:color/white"
app:menu="#menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
fragment one layout:
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fragment 1"
android:layout_gravity="center"
android:gravity="center"
android:background="#FF5722"/>
</LinearLayout>
frament one java:
public class FirstFragment extends Fragment{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View view = inflater.inflate(R.layout.home, container,false);
if(container==null){
Log.d("First","Null");
return view;
}Log.d("First"," Not Null");
return null;
}
}
use this in switch
switch(menuItem.getItemId()) {
case R.id.nav_first_fragment:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new FirstFragment()).commit();
break;
case R.id.nav_second_fragment:
getSupportFragmentManager().beginTransaction().replace(R.id.container, new SecondFragment()).commit();
break;
}
and make sure you give the correct IDs to the switch. And "container" is the ID for the layout of the activity_main.xml
just give the ID to main Layout like
android:id="#+id/container"

using layout file for fragment in Navigation drawer layout

I have an android app code that uses the navigation drawer layout with fragments as the main content.
So far I have had a specific fragment class for all the fragment items in my drawer. Now I do however have a different layout I want to get as an item in my drawer as well. The layout is a LiniarLayout and defined in xml characteristic.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_device_address"
android:textSize="18sp"/>
<Space android:layout_width="5dp"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/device_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_state"
android:textSize="18sp"/>
<Space android:layout_width="5dp"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/connection_state"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/disconnected"
android:textSize="18sp"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_data"
android:textSize="18sp"/>
<Space android:layout_width="5dp"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/data_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/no_data"
android:textSize="18sp"/>
</LinearLayout>
<ExpandableListView android:id="#+id/gatt_services_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
in my main activity I preload the fragments in the onCreate
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//create adapters early
mAdapter = new DeviceAdapter(this, false);
mFilterAdapter = new DeviceAdapter(this, true);
setContentView(R.layout.activity_main);
mFragmentManager = getFragmentManager();
mNavigationDrawerFragment = (NavigationDrawerFragment)
mFragmentManager.findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
mDevices = new HashMap<String, ScanResultContent.BtLeDeviceItem>();
mFilteredDevices = new HashMap<String, ScanResultContent.BtLeDeviceItem>();
//setup fragment 1
mScanResultFragment = new ResultListFragment();
//setup fragment 2
mFilteredScanResultFragment = new ResultListFragment();
mScanResultFragment.setListAdapter(mAdapter);
//setup fragment 3
mDeviceInfoFragment = DeviceInfoFragment.newInstance("");
// Sets up UI references for the Device Info viewer.
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataField = (TextView) findViewById(R.id.data_value);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mFilteredScanResultFragment.setListAdapter(mFilterAdapter);
// setup default fragment shown
mFragmentManager.beginTransaction().add(R.id.container, mScanResultFragment).commit();
}
I have tried to get the layout loaded into a fragment using the DeviceInfoFragment class:
public class DeviceInfoFragment extends Fragment {
public DeviceInfoFragment(){
super();
}
public static DeviceInfoFragment newInstance(String text) {
DeviceInfoFragment f = new DeviceInfoFragment();
Bundle b = new Bundle();
b.putString("text", text);
f.setArguments(b);
return f;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.gatt_characteristics_layout, container, false);
return v;
}
}
I want to be able to switch between the fragments using this (which have worked fine except for the new fragment 3):
#Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
Fragment f = null;
switch (position+1){
case 1:
f = mScanResultFragment;
mTitle = getString(R.string.title_devicescan);
break;
case 2:
f = mFilteredScanResultFragment;
mTitle = getString(R.string.title_results);
break;
case 3:
f = mDeviceInfoFragment;
mTitle = getString(R.string.title_device_info);
break;
}
if(f != null) {
mFragmentManager.beginTransaction()
.replace(R.id.container, f)
.commit();
}
restoreActionBar();
}
It does however not seem to work as the line:
mGattServicesList.setOnChildClickListener(servicesListClickListner);
fails with
E/AndroidRuntime(30644): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setOnChildClickListener(android.widget.ExpandableListView$OnChildClickListener)' on a null object reference
Can anyone tell me what I am doing wrong here?

No view found for id 0x7f090058 for fragment

I'm doing an app that uses Google Maps APIs (with two separate maps), and I want to use a navigation drawer to switch between the two maps (fragments).
I created the main activity with the pre-compiled Navigation Drawer Activity in android studio, and here is the pieces of code:
The main activity uses this layout:
activity_main_activity2.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.radonmap.radonmap.MainActivity2">
<FrameLayout android:id="#+id/container" android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<fragment android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width" android:layout_height="match_parent"
android:layout_gravity="start" android:name="it.radonmap.radonmap.NavigationDrawerFragment"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Here is the code which calls the .replace() method:
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
//do something
break;
case 1:
fragment = new FragPunti();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager;
fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.containerPunti,fragment).commit();
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
FragPunti.java
public class FragPunti extends android.support.v4.app.Fragment {
public FragPunti(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.frag_punti, null);
return rootView;
}
}
frag_punti.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/containerPunti">
<FrameLayout
android:id="#+id/framePunti"
android:layout_width="0px"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16dp"
android:text="Punti"/>
</FrameLayout>
</FrameLayout>
And here is the logcat trace:
04-30 19:17:45.823 20909-20909/it.radonmap.radonmap E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: it.radonmap.radonmap, PID: 20909
java.lang.IllegalArgumentException: No view found for id 0x7f090058 (it.radonmap.radonmap:id/containerPunti) for fragment FragPunti{36b6aaa5 #2 id=0x7f090058}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:945)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:456)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5274)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
I had already look for a solution but with no results.
Hope someone can help me.
You should pass id of container for fragment, and that's a view in which you want to show fragment. It is in activity, not in fragment you want to show. So change replace(R.id.containerPunti, fragment) to replace(R.id.container, fragment).

How to add map fragment programmatically

I would like add this xml fragment programmatically to other fragments.
Is it possible?
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
In XML you can add a placeholder container:
<FrameLayout
android:id="#+id/mapContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
And then in code you can do:
FragmentManager fm = getChildFragmentManager();
SupportMapFragment supportMapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.mapContainer, supportMapFragment).commit();
Make a layout like:
<FrameLayout
android:id="#+id/layout_mapContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="0"
android:background="#android:color/transparent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</FrameLayout>
In Activity declare :
FrameLayout mapLayout = (FrameLayout)findViewById(R.id.layout_mapContainer);
initialise map like this:
private void initialiseMap() {
FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
SupportMapFragment mFRaFragment = new MapFragmentActivity();
mTransaction.add(mapLayout.getId(), mFRaFragment);
mTransaction.commit();
try {
MapsInitializer.initialize(context);
} catch (Exception e) {
e.printStackTrace();
}
}
Here MapFragmentActivity is class extends SupportMapFragment

Android Drawer Layout is Displaying under fragment content

I am adding a drawer layout to my Activity which uses fragments. I've implemented this just as described here per the android documentation. And the drawer layout Adapter and View all work in that they show up, but the drawer extends "under" the fragment content. Here is a picture of what is happening:
Does anyone know why this might be? My code for the activity's xml, and the activity add fragment is below:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm_list); // for drawer navigation
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(android.R.id.content,
new AlarmListFragment());
fragmentTransaction.commit();
setUpDrawer(fragmentManager);
}
private void setUpDrawer(FragmentManager fm) {
String[] drawerItems = getResources().getStringArray(
R.array.drawer_array);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ListView drawerList = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
drawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.item_nav_drawer, drawerItems));
// Set the list's click listener
drawerList.setOnItemClickListener(new
DrawerItemClickListener(drawer,drawerList,drawerItems,fm));
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/alarm_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</FrameLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
Do I have to set a z-index somewhere? I can provide any further info needed I'd just really like to figure this out!
I don't what produces this issue , but to solve it u have to add the fragment to the content of your FrameLayout which has the id = content_frame.
So edit this line
fragmentTransaction.replace(android.R.id.content,
new AlarmListFragment());
to be
fragmentTransaction.replace(R.id.content_frame,
new AlarmListFragment());
You can move the drawer layout below your Fragment container in your XML. this will render the DrawerLayout in the forward view of the app. just be sure not to cover the fragment container with the parent container of the drawer so that your fragment will be accessible when you need it.
<RelativeLayout
android:id="#+id/my_parent_container"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:id="#+id/fragment_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"></FrameLayout>
<android.support.v4.widget.DrawerLayout
android:id="#+id/my_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id=#+id/drawer_pane"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="end" />
<ListView xmlns="http://schemas.android.com/apk/res/android"
android:layout_width="280dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:id="#+id/menu_list"
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>

Categories