0

我有以下 XML 布局:

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <ScrollView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:fillViewport="true"
                    android:layout_above="@+id/adcontent1"
                    android:background="#0000FF">

                    <TextView
                    android:id="@+id/tempview"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>

                </ScrollView>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FF0000"
                    android:layout_alignParentBottom="true"
                    android:id="@+id/adcontent1" >

                    <com.google.ads.AdView
                        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
                        android:id="@+id/adview1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:adSize="BANNER"
                        app:adUnitId="lah-di-da"
                        android:layout_alignParentBottom="true"
                        android:layout_centerHorizontal="true">

                    </com.google.ads.AdView>

                 </RelativeLayout>

            </RelativeLayout>

问题是,由于某种原因,wrap_content高度AdView RelativeLayout属性导致整体RelativeLayout占据整个屏幕。如果我设置了一个硬值(50px),那么我会ScrollView占据整个屏幕 - 50px(就像我想要的那样,除了RelativeLayout高度应该等于AdView高度。有谁知道为什么AdView强迫父母RelativeLayout填满屏幕?

注意:这些背后有布局,但它们对这个特定问题没有影响(通过设置 height = 50px 进行测试)。

4

2 回答 2

2

尝试将广告的高度设置为“50dp”并发布您的结果

于 2013-05-02T12:09:04.190 回答
1

由于android:layout_centerHorizontal="true"不会使用wrap_content(它可以使用,fill_parent因为它知道需要居中的区域)。删除 CenterHorizo​​ntal 代码并使用 wrap_content 而不是提供不允许动态提供广告的高度值。

于 2013-05-06T18:56:44.440 回答