android - Make fragment totally inside framelayout -
in app, want keep same ad banner @ bottom of screens, use 1 activity multiple fragments.
in activity's layoutfile(activity_mail.xml), have framelayout container of fragments , adview @ bottom show banner ads admob.
<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" tools:ignore="mergerootframe"> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"/> <fragment android:id="@+id/adfragment" android:name="com.jiyuzhai.wangxizhishufazidian.mainactivity$adfragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" /> </relativelayout>
layout of fragment replace existing fragment
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:background="@drawable/theme_color" android:layout_alignparenttop="true" android:text="topbar in fragment" android:textcolor="@android:color/white" android:textsize="30sp"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:background="@drawable/theme_color" android:layout_alignparentbottom="true" android:text="bottombar in fragment" android:textcolor="@android:color/white" android:textsize="30sp"/> </relativelayout>
code replace existing fragment
fragment = new linmofragment(); fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.setcustomanimations(r.anim.fade_in, r.anim.fade_out, r.anim.fade_in, r.anim.fade_out); fragmenttransaction.replace(r.id.container, fragment); fragmenttransaction.commit();
but when replace fragments in container, bottom area of fragment hide adview, in other words, fragment out of framelayout, want fragment totally inside container. possible?
the following want
and get(the ad banner hide bottombar of fragment)
any idea?
by way, find there no way keep same banner screens multiple activities in android, many people on said need use single activities multiple fragments, can add/remove fragments dynamically without reload new banner, but, there no code found approach, try myself. if have better solutions, please me.
try this:
<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" tools:ignore="mergerootframe"> <fragment android:id="@+id/adfragment" android:name="com.jiyuzhai.wangxizhishufazidian.mainactivity$adfragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" /> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@id/adfragment" /> </relativelayout>
the changes made original layout file moving adfragment definition above frame layout, made frame layout height wrap content, , added layout_above
attribute make frame layout appear above ad fragment.
an alternative approach have been use vertical linear layout frame layout first layout weight of 1 (and ad fragment not have layout weight).
by way, fragment contained within frame layout. frame layout being overlapped ad fragment in original layout. above suggestion makes there no overlap.
hope helps.
Comments
Post a Comment