Reputation: 1170
Hi following is my code, i want AdView to be displayed at the bottom of the screen but in my code its appearing below the last control, I set gravity as bottom as well as layout-gravity as bottom event though there is no luck for me,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/playscreenbg"
tools:context="com.exp.exp.ExpActivity"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/ll_utilities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right">
<Button
android:id="@+id/btn_highscore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_highscore_selector"
android:onClick="onClickLevels"
android:enabled="false" />
<Button
android:id="@+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_sound_off_selector"
android:onClick="onClickLevels"
android:enabled="false" />
</LinearLayout>
<ImageView
android:id="@+id/img_Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:src="@drawable/logo" />
<LinearLayout
android:id="@+id/ll_level_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/main_easy_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/btn_easy_selector"
android:onClick="onClickLevels"
android:shadowRadius="3.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
<Button
android:id="@+id/main_normal_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_normal_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
<Button
android:id="@+id/main_hard_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_hard_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewLandingPage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:gravity="bottom"
android:layout_gravity="bottom"
/>
Please help me.
Upvotes: 1
Views: 4559
Reputation: 66
// Replace with your xml file code
<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">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/playscreenbg"
tools:context="com.exp.exp.ExpActivity"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_utilities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right">
<Button
android:id="@+id/btn_highscore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_highscore_selector"
android:onClick="onClickLevels"
android:enabled="false" />
<Button
android:id="@+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_sound_off_selector"
android:onClick="onClickLevels"
android:enabled="false" />
</LinearLayout>
<ImageView
android:id="@+id/img_Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:src="@drawable/logo" />
<LinearLayout
android:id="@+id/ll_level_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/main_easy_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/btn_easy_selector"
android:onClick="onClickLevels"
android:shadowRadius="3.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
<Button
android:id="@+id/main_normal_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_normal_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
<Button
android:id="@+id/main_hard_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_hard_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
</LinearLayout>
</LinearLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewLandingPage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Upvotes: 0
Reputation: 2057
u should use weight and weightSum properties for ur linear layout.
try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher"
android:orientation="vertical"
tools:context="com.exp.exp.ExpActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:id="@+id/ll_utilities"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="right"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_highscore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:enabled="false"
android:onClick="onClickLevels" />
<Button
android:id="@+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
android:enabled="false"
android:onClick="onClickLevels" />
</LinearLayout>
<ImageView
android:id="@+id/img_Logo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="30dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:id="@+id/ll_level_buttons"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:orientation="vertical" >
<Button
android:id="@+id/main_easy_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/ic_launcher"
android:enabled="false"
android:onClick="onClickLevels"
android:shadowRadius="3.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/main_normal_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/ic_launcher"
android:enabled="false"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/main_hard_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/ic_launcher"
android:enabled="false"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewLandingPage"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
ads:adSize="BANNER"
android:gravity="bottom" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Upvotes: 4
Reputation: 28484
Simply add this blank view above <com.google.android.gms.ads.AdView />
view.
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
Upvotes: 2
Reputation: 11316
As @Adrian as suggested use the weight property of linear layouts.Below my snippet contains a relative parent container because the way you are setting the widgets using nested linear layouts will surely cause overdraw issues as well as bad rendering performance.Instead use a relative layout and get the desired result.Also nested weights is also bad for performance.Just saying.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/playscreenbg"
tools:context="com.exp.exp.ExpActivity"
android:orientation="vertical">
<Button
android:id="@+id/btn_highscore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_highscore_selector"
android:onClick="onClickLevels"
android:enabled="false"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/btn_sound"
android:layout_toStartOf="@+id/btn_sound"/>
<Button
android:id="@+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_sound_off_selector"
android:onClick="onClickLevels"
android:enabled="false"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<ImageView
android:id="@+id/img_Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
android:layout_below="@+id/btn_highscore"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<LinearLayout
android:id="@+id/ll_level_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_above="@+id/adViewLandingPage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:id="@+id/main_easy_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/btn_easy_selector"
android:onClick="onClickLevels"
android:shadowRadius="3.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false"/>
<Button
android:id="@+id/main_normal_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_normal_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false"/>
<Button
android:id="@+id/main_hard_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_hard_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false"/>
</LinearLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adViewLandingPage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
Upvotes: 0
Reputation: 1074
Why don't keep parent layout as RelativeLayout and adView at bottom of layout: android:layout_alignParentBottom="true"
.
Upvotes: 0
Reputation: 2088
you have to use one more linear layout for ads
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/playscreenbg"
tools:context="com.exp.exp.ExpActivity"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/ll_utilities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right"
android:gravity="right">
<Button
android:id="@+id/btn_highscore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_highscore_selector"
android:onClick="onClickLevels"
android:enabled="false" />
<Button
android:id="@+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_sound_off_selector"
android:onClick="onClickLevels"
android:enabled="false" />
</LinearLayout>
<ImageView
android:id="@+id/img_Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:src="@drawable/logo" />
<LinearLayout
android:id="@+id/ll_level_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/main_easy_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/btn_easy_selector"
android:onClick="onClickLevels"
android:shadowRadius="3.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
<Button
android:id="@+id/main_normal_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_normal_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
<Button
android:id="@+id/main_hard_button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_hard_selector"
android:onClick="onClickLevels"
android:shadowRadius="2.0"
android:textColor="#00e589"
android:textSize="20sp"
android:textStyle="bold"
android:enabled="false" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_utilities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewLandingPage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:gravity="bottom"
android:layout_gravity="bottom"
/>
</LinearLayout>
</LinearLayout>
Upvotes: 0