题
我的广告完全不显示,我想我已经遵循正确的文件,但他们仍然不会显示。该程序基本上是一个网页视图和我希望广告显示在底部。
下面有我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
</LinearLayout>
任何想法?
编辑:这是我现在有,但它仍然没有出现是相当正确的:
<?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/man.utd.headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
<WebView
android:id="@+id/webview"
android:layout_above="@id/ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
解决方案
您的问题是,web视图将屏幕上所有的空间,并没有留给广告空间。
一个的LinearLayout将在先到先得的规则分发的空间。如果第一视图需要的所有空间的第二视图不会得到任何空间..
我会用一个 RelativeLayout的和添加首先将与layout_alignParentBottom
属性,然后用layout_above="id for the adds"
添加web视图。这将确保增加总是在屏幕的底部,即使网页视图不会采取一切空间的时刻和web视图总是会高于补充说。
其他提示
我有同样的问题,我固定这种方式: 作为LinearLayout中主要布局,里面的LinearLayout(为广告),并在LinearLayout中的广告网页视图,设置WRAP_CONTENT,所以,它首先会显示一个广告,然后在屏幕的其余部分将是web视图。 例如矿的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/addmob"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<?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"
android:layout_width="fill_parent" android:id="@+id/rltvLayout1"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/linearLayoutwebview"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical">
<WebView android:id="@+id/webView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="@+id/ad_layout" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_alignParentBottom="true"
android:layout_alignBottom="@+id/home_layout">
<com.google.ads.AdView android:layout_width="wrap_content"
android:layout_height="wrap_content" ads:adUnitId="put here your ID"
ads:adSize="BANNER" android:id="@+id/adView" ads:refreshInterval="60" />
</LinearLayout>
</RelativeLayout>
不隶属于 StackOverflow