在 Android 中的 LinearLayout 底部设置 Adview 横幅
set Adview Banner at bottom of LinearLayout in Android
您好,以下是我的代码,
我希望 AdView 显示在屏幕底部,但在我的代码中它出现在最后一个控件下方,
我将重力设置为底部,将布局重力设置为底部事件,尽管我运气不好,
<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"
/>
请帮帮我
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>
为什么不将父布局保留为 RelativeLayout 并将 adView 保留在布局底部:android:layout_alignParentBottom="true"
。
正如@Adrian 所建议的那样,使用线性 layouts.Below 的权重 属性 我的代码片段包含一个相对父容器,因为您使用嵌套线性布局设置小部件的方式肯定会导致透支问题,因为糟糕的渲染 performance.Instead 使用相对布局并获得所需的 result.Also 嵌套权重对于 performance.Just 来说也很糟糕。
<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>
只需在 <com.google.android.gms.ads.AdView />
视图上方添加此空白视图即可。
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
你应该为你的线性布局使用 weight 和 weightSum 属性。
试试这个
<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>
// 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>
您好,以下是我的代码, 我希望 AdView 显示在屏幕底部,但在我的代码中它出现在最后一个控件下方, 我将重力设置为底部,将布局重力设置为底部事件,尽管我运气不好,
<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"
/>
请帮帮我
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>
为什么不将父布局保留为 RelativeLayout 并将 adView 保留在布局底部:android:layout_alignParentBottom="true"
。
正如@Adrian 所建议的那样,使用线性 layouts.Below 的权重 属性 我的代码片段包含一个相对父容器,因为您使用嵌套线性布局设置小部件的方式肯定会导致透支问题,因为糟糕的渲染 performance.Instead 使用相对布局并获得所需的 result.Also 嵌套权重对于 performance.Just 来说也很糟糕。
<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>
只需在 <com.google.android.gms.ads.AdView />
视图上方添加此空白视图即可。
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
你应该为你的线性布局使用 weight 和 weightSum 属性。
试试这个
<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>
// 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>