[SOLVED] I added this to MainActivity XML file:
<FrameLayout
android:id="#+id/place_map_here"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<FrameLayout
android:id="#+id/bugfixview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#android:color/transparent"/>
and where I changed the fragments:
mapFragment = new FragmentMapView();
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.place_map_here, mapFragment, "map");
ft.commit();
Edit: Just realized that I do not use the MapFragment xml file.(older build did sorry)
I´ve changed my Fragment to a MapFragment and now my NavigationDrawer slides in behind the MapFragment :(
Code:
MapFragmant xml ( removed code)
MainActivity xml. Here is my drawer declared
<RelativeLayout 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"
tools:context=".MainActivity" >
<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=".MainActivity" >
<FrameLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#333"
android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
I hope this is the information you need to be awesome like always and help noobs like me :)
Try this hack it might help you, just change your layout to something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- hack to fix ugly black Background with maps v2 -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</FrameLayout>
</LinearLayout>
DrawerLayout needs to be the root of your layout, so try deleting the RelativeLayout. I assume you are attaching your MapFragment to the FrameLayout, main.
Also, what api version are you on? I've noticed some weird graphics bugs on api<10 including black borders and black flashing backgrounds with both map fragments and drawers.
we can solve NavigationDrawer going behind MapFragment by using view just below map fragment in the layout.
eg -
<FrameLayout
android:id="#+id/root"
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" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
Related
I have 3 fragments and im trying to use the slidinguppanel from this library https://github.com/umano/AndroidSlidingUpPanel.
But how can i use the same slidinguppanel across all fragments, so the content stays the same and i don't have to make another sliding up panel in the other layout?
This is my xml for fragment 1
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mSlideUpPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
tools:context=".fragments.Tab1"
app:umanoPanelHeight="70dp"
app:umanoShadowHeight="5dp">
<RelativeLayout 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"
tools:context=".fragments.Tab1">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewSongs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/activity_song" />
</RelativeLayout>
Having an issue with a map fragment on my one activity, basically i have created a bottom navigation view and my map fragment is going behind my bottom navigation view no matter what i do. I'm not sure how to get it to respect my layout and sit above my bottom navigation view.
I have a scrollview with all my content inside it, including the map fragment and then a bottom navigation view outside of my scroll view so that it remains fixed to the bottom of the layout.
<RelativeLayout
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"
android:fitsSystemWindows="true">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollview"
android:orientation="vertical">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- My content -->
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:layout_below="#+id/details"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="300dp"
map:cameraZoom = "15"
map:uiZoomControls = "true" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/toolbar_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:layout_alignParentBottom="true"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_toolbar"
android:background="#drawable/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
app:menu="#menu/toolbar_item" />
</LinearLayout>
</RelativeLayout>
update code
android:layout_above="#+id/toolbar_footer"
...
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollview"
android:orientation="vertical"
android:layout_above="#+id/toolbar_footer"
android:fillViewport="true">
...
I have an activity where I show a map. I want to can change when click an item on my navigation drawer with a different fragment.
I have next main xml:
<?xml version="1.0" encoding="utf-8"?>
<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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.main.activities.Activity_main">
<include layout="#layout/my_bar" />
<android.support.design.widget.NavigationView
android:layout_marginTop ="45dp"
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_menu"
app:itemIconTint="#000000"
android:background="#FFFFFF"
app:itemTextColor="#000000"
app:headerLayout="#layout/navigation_header">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Bar layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/my_bar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar -->
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/primary_color"
android:titleTextAppearance="#color/text_and_icon_color"
app:popupTheme="#style/Theme.AppCompat"
android:elevation="1dp"
android:textAlignment="center"
android:layout_height="45dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My app"
android:layout_gravity="center"
android:id="#+id/toolbar_title"
android:layout_weight="1"
android:textSize="24sp"
android:textColor="#android:color/white" />
</android.support.v7.widget.Toolbar>
<include layout="#layout/my_content" />
</LinearLayout>
My content:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/my_content"
android:background="#color/window_background_color">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="#+id/adView"/>
</RelativeLayout>
I try to replace the map with a fragment :
<FrameLayout 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"
tools:context="com.main.activities.catalog">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_blank_fragment" />
</FrameLayout>
I call with this code:
catalog fragment2 = new catalog();
android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.my_content, fragment2, "fragment2");
fragmentTransaction.commit();
But my map isn't replaced with new fragment. Where I do wrong?
As #MikeM says in a comment to your question, the problem is that my_content.xml contains a static fragment specified directly in the XML. FragmentManager will not replace such a fragment dynamically at run time. Instead, you should remove the fragment tag and add the map fragment dynamically in onCreate(). Typically this is done with a FrameLayout but I think it will also work with a RelativeLayout.
For more information, see the Fragment Developer Guide.
In my application there is a google map, When user clicks on a pin a specific layout will display exactly like SncakBar, Layout contains some Buttons and TextViews. Please help me how can I add layout over google map.
XML file of Main layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/ToolBarStyle"
android:id="#+id/toolbar_actionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="12dp"
android:minHeight="#dimen/abc_action_bar_default_height_material" />
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_actionbar">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="match_parent" >
</FrameLayout>
<!--<!– android:layout_marginTop="?android:attr/actionBarSize"–>-->
<fragment android:id="#+id/fragment_drawer"
android:name="com.example.muhammad.shopplus.NavigationDrawerFragment"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer" />
<FrameLayout
android:id="#+id/container_"
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="match_parent" >
</FrameLayout>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.DrawerLayout>
Thanks in advance.
You can create a extra layout at the bottom of the screen by using Framelayout or inside of your current layout. At the beginning, it will be invisible. When user press somewhere, it will be visible at the bottom. This is my suggestions. You can try if it works.
I am using ViewPager and RecyclerView in a FrameLayout.
<FrameLayout 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"
tools:context=".HomeActivity">
<android.support.v4.view.ViewPager
android:id="#+id/top_container"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/regular_view"
android:clipToPadding="false"
android:paddingTop="300dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
I want to hide the ViewPager on Scroll of RecyclerView vertically. It is working.
However the scroll of ViewPager is not working. Why it is happening ?
here is an example for drawer layout used to implement left navigation Drawer
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<include
android:id="#+id/app_bar_main_activity"
android:layout_width="fill_parent"
android:layout_height="#dimen/app_bar_height"
layout="#layout/app_bar" />
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
<fragment
android:id="#+id/navigation_drawer"
android:layout_width="280dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:name="sub.fragments.NavigationDrawer"
tools:layout="#layout/fragment_navigation_drawer"
app:layout="#layout/fragment_navigation_drawer">
</fragment>
in this Linear layout acts as host for different layout for separate Fragments which can be replaced with framlayout
and next Fragment can be anything you want, here's a fragment you can have RecyclerView