Supportmapfragment With A Custom Layout, Possible?
Solution 1:
If you want to create a SupportMapFragment with a custom layout, I prefer to extend the android.support.v4.app.Fragment
from the Support Library and inflate your custom XML with the com.google.android.gms.maps.MapView
and other views there.
But be careful to forward the livecycle methods to this MapView
as quoted here.
Solution 2:
I added a LinearLayout above the map. I used this layout for the buttons:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/llPlaces"android:orientation="horizontal"android:background="@color/ACGris"><Buttonandroid:id="@+id/btn1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="BUTTON1"/><Buttonandroid:id="@+id/btn2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="BUTTON2"/><Buttonandroid:id="@+id/btn3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="BUTTON3"/>
And then I created a class which extends SupportMapFragment
publicclassFrgMapasextendsSupportMapFragment{
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewviewMain=super.onCreateView(inflater, container, savedInstanceState);
ViewviewButtons= inflater.inflate(R.layout.layout_buttons, null);
FrameLayoutmainChild= (FrameLayout) ((ViewGroup)viewMain).getChildAt(0);
mainChild.addView(viewButtons);
Buttonbtn1= (Button) viewMain.findViewById(R.id.btn1);
btn1.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
Toast.makeText(getActivity(), "TuTa :)", Toast.LENGTH_LONG).show();
}
});
return viewMain;
}
Hope this works for you
Solution 3:
com.google.android.gms.maps.MapView
is a View
that you can embed in your layouts.
Solution 4:
You can override onCreateView in the class you derive from SupportMapFragment. You can call super.onCreateView and then insert the result into a custom ViewGroup you inflater or instantiate. Here's some sample code
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FrameLayoutlayout= (FrameLayout) inflater.inflate(R.layout.my_layout,
container, false);
Viewv=super.onCreateView(inflater, container, savedInstanceState);
layout.addView(v, 0);
return layout;
}
Post a Comment for "Supportmapfragment With A Custom Layout, Possible?"