Question

I have my smart banner working, but I'd like it to appear at the bottom of my app instead of at the top where it currently is--preferably with 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>

Appreciate any help I can get, thank you!

Was it helpful?

Solution

Set the following RelativeLayout.LayoutParams for your ad:

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

Add this code after layout.addView(adView);

OTHER TIPS

And another linear layout at the end inside your relative layout. Set android: layout_gravity to bottom for this linear layout and add your adview to this linear layout. Worked for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top