gpt4 book ai didi

java - admob 智能横幅需要位于应用程序底部(通过 java)

转载 作者:行者123 更新时间:2023-12-02 05:53:59 25 4
gpt4 key购买 nike

我的智能横幅正在运行,但我希望它出现在我的应用程序的底部,而不是当前所在的顶部——最好是使用 java。

Main.java

public class MainActivity extends Activity {

private AdView adView;

private static final String AD_UNIT_ID = "unique_id_here";

private ImageView mPlayPic;

MediaPlayer mRainSound;

private ImageView mBgImg;

private ImageView mNextPicButton;

private int currentImage = 0;

int[] images = { R.drawable.pic4, R.drawable.pic1, R.drawable.pic5, R.drawable.pic8, R.drawable.rsz_1pic9, R.drawable.rsz_pic7 };


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_rain);

// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);

// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
RelativeLayout layout = (RelativeLayout) findViewById(R.id.relativeLayout);
layout.addView(adView);

// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("0C179D00E6B9B79C492DCCA6A64B1FA9") //gotten from running as Debug and reading logcat
.build();

// Start loading the ad in the background.
adView.loadAd(adRequest);

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/bgImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:src="@drawable/pic4"
android:scaleType="fitXY" />

<ImageView
android:id="@+id/picImage"
android:layout_width="110dp"
android:layout_height="110dp"
android:padding="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:contentDescription="@null"
android:src="@drawable/opaq_mountain" />

<ImageView
android:id="@+id/playImage"
android:layout_width="110dp"
android:layout_height="110dp"
android:padding="10dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:contentDescription="@null"
android:src="@drawable/square_play_opac" />


</RelativeLayout>

感谢我能得到的任何帮助,谢谢!

最佳答案

为您的广告设置以下RelativeLayout.LayoutParams:

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) adView.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
adView.setLayoutParams(params);

layout.addView(adView);之后添加此代码

关于java - admob 智能横幅需要位于应用程序底部(通过 java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23277255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com