two layout files:
activity_maps.xml
<framelayout android:id="@+id/fragment_container" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <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:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.jawadh.startthreeproject.mapsactivity" /> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/place_autocomplete_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:name="com.google.android.gms.location.places.ui.placeautocompletefragment" /> </framelayout >
second.xml
<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/view_container" android:layout_height="50dip" android:layout_width="50dip" > <button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" /> <textview android:id="@+id/textviewsource" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <textview android:id="@+id/textviewdest" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </framelayout>
in activity, once mapsactivity gets loaded , working fine. want load view of second.xml on exisiting view. so, trying this:
final framelayout framelayout = (framelayout)view.inflate(getapplicationcontext(),r.layout.second,null); final button button = (button)framelayout.findviewbyid(r.id.button);; button.setbackgroundcolor((color.gray)); button.settext("direction"); button.sety(300); button.setx(300); textview textviewsource = (textview)framelayout.findviewbyid(r.id.textviewsource); textviewsource.settext(place.getaddress().tostring()); textviewsource.settextcolor(color.black); textviewsource.setbackgroundcolor(color.white); framelayout.setbackgroundcolor(color.blue);
expectation: last part of code should put te second.xml view(framelayout) on exisiting view.
warning: not use application context inflating views!
you created second layout here:
final framelayout framelayout = (framelayout)view.inflate(this, r.layout.second,null);
now have attach view hierarchy. fragment container sounds nice enough:
framelayout container = (framelayout) findviewbyid(r.id.fragment_container); framelayout.layoutparams lp = new framelayout.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent); container.addview(framelayout, lp);
edit
alternatively inflate , attach new view in 1 go so:
framelayout container = (framelayout) findviewbyid(r.id.fragment_container); final framelayout framelayout = (framelayout)view.inflate(this, r.layout.second, container);
...because framelayout
provide these layoutparams
default:
/** * returns set of layout parameters width of * {@link android.view.viewgroup.layoutparams#match_parent}, * , height of {@link android.view.viewgroup.layoutparams#match_parent}. */ @override protected layoutparams generatedefaultlayoutparams() { return new layoutparams(layoutparams.match_parent, layoutparams.match_parent); }
Comments
Post a Comment