我在cordova cli中创建了一个项目,然后通过gradle将其导入到android studio中。我设法将admob放入项目中,但横幅位于布局的顶部。我想把它放在布局的底部。有人可以帮忙吗? 这是androidmanifest.xml中的代码:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="xxx" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:name="com.google.android.gms.ads.AdActivity" />
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
</manifest>
这是mainactivity.java中的代码
import android.os.Bundle;
import org.apache.cordova.*;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
public class MainActivity extends CordovaActivity
{
private AdView mAdView;
private String ad_unit_id = "xxx";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
// Set Ads
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
// Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
mAdView = new AdView(this);
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId(ad_unit_id);
// Create an ad request.
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
// Add the AdView to the view hierarchy.
layout.addView(mAdView);
// Start loading the ad.
mAdView.loadAd(adRequestBuilder.build());
// Show Ads
addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
@Override
public void onResume() {
super.onResume();
// Resume the AdView.
mAdView.resume();
}
@Override
public void onPause() {
// Pause the AdView.
mAdView.pause();
super.onPause();
}
@Override
public void onDestroy() {
// Destroy the AdView.
mAdView.destroy();
super.onDestroy();
}
}