我的页面有一个页脚,其中包含定义为RelativeLayout
的导航图像按钮(后退和前进)。
<!-- Footer aligned to bottom. This is for the menu -->
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/bottom_menu_bgd"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<ImageButton
android:id="@+id/bottom_menu_btn_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/bottom_menu_home"/>
<ImageButton
android:id="@+id/bottom_menu_btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/bottom_menu_play"
android:visibility="visible"/>
</RelativeLayout>
我想在页脚顶部添加横幅广告。 我试图在RelativeLayout中插入一个LinearLayout(使用横幅广告),但它在页脚的相同位置显示了横幅。
如何移动横幅广告才能在页脚顶部显示?
答案 0 :(得分:1)
将横幅 AdView 放在RelativeLayout的末尾,并将android:layout_above="@+id/footer"
添加到 AdView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Footer aligned to bottom. This is for the menu -->
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:background="@drawable/bottom_menu_bgd"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<ImageButton
android:id="@+id/bottom_menu_btn_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/bottom_menu_home"/>
<ImageButton
android:id="@+id/bottom_menu_btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@drawable/bottom_menu_play"
android:visibility="visible"/>
</RelativeLayout>
<!-- Add your Banner AdView here -->
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/footer"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
</RelativeLayout>
答案 1 :(得分:0)
您可以对所有布局应用权重。 将weight_sum = 10分配给父布局。 然后
layout_weight="8" ---to layout above footer,
layout_weight = "1" ---to footer
layout_weight = "1" ---to banner ad
答案 2 :(得分:0)
尝试使用此演示代码它将包含屏幕底部的两个按钮和底部图像上方的Adview:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/action_bar_hover"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<RelativeLayout
android:id="@+id/my_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<ImageButton
android:id="@+id/bottom_menu_btn_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@android:drawable/alert_dark_frame" />
<ImageButton
android:id="@+id/bottom_menu_btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:src="@android:drawable/alert_dark_frame"
android:visibility="visible" />
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="MEDIUM_RECTANGLE"
android:layout_above="@id/my_view"
ads:adUnitId="@string/banner_home_footer"/>
</RelativeLayout>