I have an app that I am working on for fun right now to learn more about android, but I have ran into a small issue.
When I start up the app in portrait my main login page shows up with an ad, every thing works fine. Then when the orientation is changed to landscape, the layout is changed to my landscape version, but then the ad doesn't show up. My Ad log says that the Ad is not visible, Not refreshing ad.
If i start the app in Landscape and switch to portrait it will do the same thing.
I was thinking about locking the screen orientation, but that's a workaround and won't address the real issue.
Here are my files im working with. I have tried changing the width and height attributes in each one, I may just not be doing it correctly though.
fragment_main.xml
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity?PlaceholderFragment"
android:id="@+id/loginLayout">
<RelativeLayout
android:background="@drawable/div_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/relativeLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/userNameInput"
android:hint="User Name"
android:fontFamily=""
android:textStyle="bold"
android:layout_alignBottom="@+id/imageView"
android:layout_alignLeft="@+id/passwordInput"
android:layout_alignStart="@+id/passwordInput"
android:layout_alignRight="@+id/passwordInput"
android:layout_alignEnd="@+id/passwordInput" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/passwordInput"
android:hint="Password"
android:layout_below="@+id/userNameInput"
android:layout_centerHorizontal="true"
android:fontFamily=""
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register_btn_text"
android:id="@+id/buttonRegister"
android:layout_below="@+id/buttonLogin"
android:layout_alignLeft="@+id/buttonLogin"
android:layout_alignStart="@+id/buttonLogin"
android:layout_alignRight="@+id/buttonLogin"
android:layout_alignEnd="@+id/buttonLogin"
android:background="@drawable/btn_style"
android:paddingBottom="1dp"
android:textStyle="bold"
android:fontFamily=""
android:paddingTop="2dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login_btn_text"
android:id="@+id/buttonLogin"
android:layout_below="@+id/passwordInput"
android:layout_alignLeft="@+id/passwordInput"
android:layout_alignStart="@+id/passwordInput"
android:layout_alignRight="@+id/passwordInput"
android:layout_alignEnd="@+id/passwordInput"
android:background="@drawable/btn_style"
android:paddingBottom="1dp"
android:fontFamily=""
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
land/Fragment_main.xml
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity?PlaceholderFragment"
android:id="@+id/loginLayout">
<RelativeLayout
android:background="@drawable/div_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/userNameInput"
android:hint="User Name"
android:fontFamily=""
android:textStyle="bold"
android:layout_alignLeft="@+id/passwordInput"
android:layout_alignStart="@+id/passwordInput"
android:layout_alignRight="@+id/passwordInput"
android:layout_alignEnd="@+id/passwordInput" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/passwordInput"
android:hint="Password"
android:layout_below="@+id/userNameInput"
android:layout_centerHorizontal="true"
android:fontFamily=""
android:textStyle="bold" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register_btn_text"
android:id="@+id/buttonRegister"
android:layout_below="@+id/buttonLogin"
android:layout_alignLeft="@+id/buttonLogin"
android:layout_alignStart="@+id/buttonLogin"
android:layout_alignRight="@+id/buttonLogin"
android:layout_alignEnd="@+id/buttonLogin"
android:background="@drawable/btn_style"
android:paddingBottom="1dp"
android:textStyle="bold"
android:fontFamily=""
android:paddingTop="2dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login_btn_text"
android:id="@+id/buttonLogin"
android:layout_below="@+id/passwordInput"
android:layout_alignLeft="@+id/passwordInput"
android:layout_alignStart="@+id/passwordInput"
android:layout_alignRight="@+id/passwordInput"
android:layout_alignEnd="@+id/passwordInput"
android:background="@drawable/btn_style"
android:paddingBottom="1dp"
android:fontFamily=""
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
adfragment.xml
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
xmlns:ads="http://ift.tt/GEGVYd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:id="@+id/adsmain">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
land/adFragment.xml
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
xmlns:ads="http://ift.tt/GEGVYd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:id="@+id/adsmain">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
xmlns:ads="http://ift.tt/GEGVYd"
android:id="@+id/maincontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity?PlaceholderFragment"
tools:ignore="MergeRootFrame">
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/main_header_selector"
android:layout_above="@+id/adView">
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
land/activity_main.xml
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
xmlns:ads="http://ift.tt/GEGVYd"
android:id="@+id/maincontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity?PlaceholderFragment"
tools:ignore="MergeRootFrame">
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/main_header_selector"
android:layout_above="@+id/adView">
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
The Fragment_main and adfragment both get placed inside my activity_main.xml The fragments render just like they should its just the ad container that I use that might be causing the problems
Hopefully a designer and nudge me in the proper direction.
Thanks in advanced.
Aucun commentaire:
Enregistrer un commentaire