AdMob 获取广告时显示进度对话框
我的应用程序有一个活动,其中广告最好放置在屏幕中央。我已将其他元素设置为相对于广告位于上方或下方。我喜欢广告出现时的样子,但当活动开始时,一切都混在一起了。
我想要做的是在 AdMob 投放广告时广告所在的空间中显示一个进度对话框。
我已采用此处记录的 XML 方式实施广告:http://code .google.com/mobile/ads/docs/android/banner_xml.html
有人能让我走上正确的道路吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.aydabtu.BroadcastSMS"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/megaphone_320x480"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="left"
android:text="@string/num_messages"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@+id/num_msgs_title"
android:layout_above="@+id/smsMsgBody_editText"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="0"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@+id/num_msgs"
android:layout_toRightOf="@id/num_msgs_title"
android:layout_alignTop="@id/num_msgs_title"
/>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:singleLine="false"
android:lines="5"
android:minLines="5"
android:gravity="top|left"
android:id="@id/smsMsgBody_editText"
android:hint="@string/sms_edittext"
android:layout_above="@+id/body_len"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="right"
android:paddingRight="10sp"
android:text="0"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@id/body_len"
android:layout_above="@+id/ad"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="left"
android:paddingRight="10sp"
android:text="@string/clear_text"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@+id/clear_text"
android:layout_above="@id/ad"
/>
<com.admob.android.ads.AdView
android:id="@id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="@drawable/black"
myapp:primaryTextColor="@drawable/white"
myapp:secondaryTextColor="@drawable/drkGrey"
android:layout_above="@+id/broadcastMsg_button"
/>
<Button
android:layout_height="wrap_content"
android:id="@id/broadcastMsg_button"
android:layout_width="fill_parent"
android:text="@string/broadcast_sms_button"
android:layout_centerInParent="true"
/>
</RelativeLayout>
My app has an activity where the ad is best placed in the center of the screen. I've made the other elements sit relative to the ad either above or below. I like the way it looks when the ad is present, but when the activity starts everything is mashed together.
What I would like to do is display a progress dialog in the space where the ad will go if AdMob delivers an ad.
I have implemented my ads in the XML way documented here: http://code.google.com/mobile/ads/docs/android/banner_xml.html
Can someone put me on the right path?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.aydabtu.BroadcastSMS"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/megaphone_320x480"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="left"
android:text="@string/num_messages"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@+id/num_msgs_title"
android:layout_above="@+id/smsMsgBody_editText"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="0"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@+id/num_msgs"
android:layout_toRightOf="@id/num_msgs_title"
android:layout_alignTop="@id/num_msgs_title"
/>
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:singleLine="false"
android:lines="5"
android:minLines="5"
android:gravity="top|left"
android:id="@id/smsMsgBody_editText"
android:hint="@string/sms_edittext"
android:layout_above="@+id/body_len"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="right"
android:paddingRight="10sp"
android:text="0"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@id/body_len"
android:layout_above="@+id/ad"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="left"
android:paddingRight="10sp"
android:text="@string/clear_text"
android:background="@drawable/semiTransparentLt"
android:textColor="@drawable/black"
android:textStyle="bold"
android:id="@+id/clear_text"
android:layout_above="@id/ad"
/>
<com.admob.android.ads.AdView
android:id="@id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="@drawable/black"
myapp:primaryTextColor="@drawable/white"
myapp:secondaryTextColor="@drawable/drkGrey"
android:layout_above="@+id/broadcastMsg_button"
/>
<Button
android:layout_height="wrap_content"
android:id="@id/broadcastMsg_button"
android:layout_width="fill_parent"
android:text="@string/broadcast_sms_button"
android:layout_centerInParent="true"
/>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说在现在有 AdView 的地方放置一个框架布局。
在 AdView 中放置一个 AdView 和圆形 ProgressBar。一旦 AdView 出现,可能需要一些调整来隐藏 ProgressBar,但应该可以。
如果您发布确切的 XML。我将给出更详细的解释。
I'd say place a frame layout where you have the AdView now.
Place an AdView and circular ProgressBar within the AdView. Might need some tweaking to hide the ProgressBar once the AdView appears, but should be work.
If you post your exact XML. I will give a more detailed explanation.