我正在尝试在 Android 上创建一个带有广告的页面(使用 ad mob)。以下我正在使用的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adView_relative_layout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Primary Screen sssssssss ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss sssssssssssssssssssssssssssssssss ssssssssssssssssssssssssssssssssssssssssss sssssssssssssssssssssssssssssssssssssssss ssssssssssssss s jkjkljlkjkljsjkjlkjskjkjkl jkljkljkl jkljlkj kljkljkl jkljlkjkljkl jkljlkjkljlkjlk jlkjlkjlkjlkjlkjlkj jkljlkjlkjlkjlkjlkjlkjlkjlk jlkjlkjlkjkljlkjlkj lkjlkjlkjklj kljlkjlkjlkjkljlkjlkjlkjlkjlkjlk lkjlkjlkjlkjlkj jlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkj lkjlkjlk lkjlkjlknigpoihgpoj k lkjcfhkl jiuvlk jkjhu hiuhjlkjliijv kjgjhhgkjjhlkkjk"
android:textSize="20sp" />
<Button
android:id="@+id/SwitchToSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Switch to Second Screen"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/adView_relative_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<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>
</RelativeLayout>
但问题是广告出现在屏幕的顶部和底部(这就是我想要的)但它覆盖了广告部分文本顶部和底部的文本(即使我向上或向下滚动)。我无法看文字
请指导如何对齐文本和滚动视图,以便我可以看到所有文本以及广告视图。
在我的 Activity.java 代码下面找到:
package com.abc.testapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.*;
import android.view.*;
import android.content.Intent;
import com.google.ads.*;
public class HomeActivity extends Activity {
/** Called when the activity is first created. */
Button screen2Button=null;
//private AdView adView;
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);
screen2Button=(Button)findViewById(R.id.SwitchToSecond);
screen2Button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent myIntent=new Intent(v.getContext(),SecondScreen.class);
startActivity(myIntent);
}
});
String s1 = getResources().getString(R.string.MY_AD_UNIT_ID);
// Create the adView
adView = new AdView(this, AdSize.BANNER, s1);
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
RelativeLayout layout = (RelativeLayout)findViewById(R.id.LinearLayout1);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_home, menu);
return true;
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}