按钮与AdView的对齐方式

时间:2013-04-12 18:47:55

标签: android alignment adview

我有一个Android应用程序布局,里面有几个按钮。我正在尝试在页面底部设置广告。请参考下面的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/MainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_color"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/adView"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_top_margin" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left|center_vertical"
                android:text=""
                android:textColor="@color/text_color"
                android:textSize="@dimen/nav_text_size" >
            </TextView>

            <Button
                android:id="@+id/ProceedToScreen31"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA1"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <Button
                android:id="@+id/ProceedToScreen32"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA2"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <Button
                android:id="@+id/ProceedToScreen33"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA3"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <Button
                android:id="@+id/ProceedToScreen34"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:drawableRight="@drawable/ic_action_name"
                android:gravity="left|center_vertical"
                android:text="@string/TA4"
                android:textColor="@color/btn_text_color"
                android:textSize="@dimen/button_text_size" >
            </Button>

            <View
                android:layout_width="match_parent"
                android:layout_height="2dip"
                android:background="@color/line_color" >
            </View>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/copyright"
                android:textColor="@color/text_color"
                android:textSize="@dimen/small_text_size" >
            </TextView>
        </LinearLayout>
    </ScrollView>

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/MY_AD_UNIT_ID"
        ads:loadAdOnCreate="true" />

</RelativeLayout>

广告完全位于页面底部作为固定页脚(根据我的要求),但随着页面的其他组件也会到达页面底部,大空间位于页面顶部页。 PLease help我如何对齐以便只有广告应该到达页面底部,所有组件应该从页面顶部开始。

4 个答案:

答案 0 :(得分:0)

这是因为滚动视图中的这一行:

android:layout_above="@+id/adView"

这样做是因为你基本上是在告诉它,“只是在adView上方,放置ScrollView。”只是删除它修复它为我。

答案 1 :(得分:0)

尝试删除

android:gravity="center_horizontal"

从顶部布局。实际上,我会删除所有对重力的引用,直到你把东西放在正确的位置,就个人而言。此外,您可能想要检查有多大

@dimen/activity_top_margin

是。它可以很好地解释你的空间。

答案 2 :(得分:0)

添加到ScrollView - &gt; android:layout_alignParentTop="true"这将删除顶部的空白区域。

此外,我建议先设置AdView,然后将ScrollView设置为android:layout_above="@+id/adView",因为ScrollView会根据AdView设置其布局有时需要首先定义不依赖于任何其他布局的布局,然后定义其他布局。

答案 3 :(得分:0)

感谢各位大家的投入,我的代码出现了问题,我在两个地方都设置了广告与Java类以及XML文件,我删除了Java中的广告代码,并将XML文件中的一小段代码更改为根据这里的建议android:layout_above =“@ + id / adView”

现在一切看起来都很好,并且符合要求。再次感谢您的时间和投入。