是否可以在 LinearLayout 内放置一个 AdView,将 AdView 宽度缩小到 180px
我正在为小屏幕设备实现布局。
为了进行测试,我使用分辨率为 240x320 的华为 Ideos U8150。
由于分辨率较小,我遇到了一个主要的空间问题。所以我想我可以将 AdMob AdView 和 TextView 放在水平 LinearLayout 中。
AdView 尺寸将占据宽度的 3/4,TextView 尺寸将占据 1/4。
在图形布局工具中,一切看起来都符合预期。但是当我在设备上运行该应用程序时,它不会在 AdView 内显示广告。我将 AdView 的背景设为红色,这样我就可以确认 AdView 实际上是可见的。它只是不显示广告。
我通过 onReceiveAd
确认我收到了广告。我在该方法中打印 AdView 的框架。其记录为原点:0,38 宽度:180,47。看起来对我来说也不错。
所以我想知道 AdMob AdView 是否能够调整其广告大小,以便它们正确显示。也许我尝试的事情是不可能的。
这是我的布局:
<LinearLayout android:id="@+id/linearLayoutAds" android:background="#F0F0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentTop="true">
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_weight="3"
android:background="#FF00"
ads:adSize="BANNER"
ads:adUnitId="foobar"
ads:loadAdOnCreate="true"
ads:refreshInterval="30"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:background="#F000"
android:gravity="right"
android:text="999"
android:textSize="45dip"
android:textStyle="bold"
/>
</LinearLayout>
I'm implementing a layout for a small screen device.
For testing I'm using a Huawei Ideos U8150 which has a resolution of 240x320.
Because of the small resolution I have a major space problem. So I thought I could put an AdMob AdView and a TextView inside of a horizontal LinearLayout.
The AdView size would take up 3/4 of the width and the TextView 1/4.
In the graphical layout tool everything looks as expected. But when I run the app on the device it doesn't display an ad inside of the AdView. I made the background of the AdView red so I can confirm that the AdView is actually visible. It just doesn't display ads.
I confirmed with onReceiveAd
that I get ads. And I print the frame of the AdView in that method. Which logs as origin: 0,38 width: 180,47. Looks okay for me too.
So I'm wondering if the AdMob AdView is able to resize its ads so they are displayed correctly. Maybe the things I try are just not possible.
That's my layout:
<LinearLayout android:id="@+id/linearLayoutAds" android:background="#F0F0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentTop="true">
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_weight="3"
android:background="#FF00"
ads:adSize="BANNER"
ads:adUnitId="foobar"
ads:loadAdOnCreate="true"
ads:refreshInterval="30"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:background="#F000"
android:gravity="right"
android:text="999"
android:textSize="45dip"
android:textStyle="bold"
/>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果线性布局的高度小于 50 dp,广告将不会展示。我没有尝试过减小宽度,但是在查看此 线程 后,它看起来像不可能将宽度减小到 180 px。
Ads won't display if your linearlayout's height becomes less than 50 dp. I have not tried reducing width , but after looking at this thread it looks like its not possible to reduce the width to 180 px.