Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4258078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:36:03+00:00 2026-05-21T05:36:03+00:00

I have two views, a game view and an admob view. I want the

  • 0

I have two views, a game view and an admob view.

I want the game view positioned at 0, 0 and with fill parent (so it covers the whole screen), and I want to admob view to be located at 50, 50 (just an example coordinates) and with fill_content.

How do I do this using FrameLayout in Android? Doesn’t matter if its via layout-xml or programatically.

I’ve spent a lot of time searching for examples and tweaking the code myself without any luck.

Specific example code is more appreciate than a link to how views generally work in Android.

Update 1:

This is my current code.

Via XML-layout:

Layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/framelayout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">

    <se.meendo.mapgame.MainMenuView android:id="@+id/mainmenuview" android:layout_width="fill_parent" android:layout_height="fill_parent" />

    <com.google.ads.AdView android:id="@+id/ad"
        android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="50dip" 
android:layout_marginRight="50dip"
    />

</FrameLayout>

Java:

public class BannerActivity extends Activity {

    @Override
    public void onCreate(final Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.banner);

        MainMenuView mmv = (MainMenuView) findViewById(R.id.mainmenuview);
        if (mmv == null) {
            mmv = new MainMenuView(this);
        }

        AdView ad = (AdView) findViewById(R.id.ad);
        if (ad != null) {
            ad = new AdView(this, AdSize.BANNER, "a14da0cf5ab5ef7");

            AdRequest request = new AdRequest();
            request.setTesting(true);
            ad.loadAd(request);

        }

    }

}

Via pure Java

public class BannerActivity extends Activity {

    @Override
    public void onCreate(final Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        FrameLayout layout = new FrameLayout(this);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        MainMenuView mmview = new MainMenuView(this);
        LayoutParams pl = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        layout.addView(mmview, pl);

        AdView adView = new AdView(this, AdSize.BANNER, "****");
        LayoutParams pelle = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        pelle.setMargins(240, 430, 0, 240);
        adView.setLayoutParams(pelle);

        //      adView.setAdListener(new MyAdListener(this));

        AdRequest request = new AdRequest();
        request.setTesting(true);
        adView.loadAd(request);

        LayoutParams pl2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        pl2.setMargins(240, 430, 0, 240);
        //      layout.addView(adView, pl2);
        layout.addView(adView);

        setContentView(layout);

    }

}

Here I trid with coordinates 240, 430 – since I know the banner is 320×50 and I wanted to try and put in the center.

The results

XML-layout: The MainMenu-view showed but not admob-view
Pure Java: The MainMenu-view showed, and the admob-view. But the admob view is shown at 0, 0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:36:04+00:00Added an answer on May 21, 2026 at 5:36 am

    Add just layout_gravity attribute in com.google.ads.AdView view as follow

    android:layout_gravity="left"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two views, one view takes the whole screen, the second view covers
I have two views, both under the NavigationController. I don't want View 1 (on
I have two views within one .xib (one view for landscape, another for portrait).
I have two views.In first view, I have a table view and I am
I'm making an iPhone game in which I have two main views, the planning
I have two views, jumpBarPortrait and jumpBarLandscape I would like to animate between the
I have two views in my ViewFlipper . One of views contains a ListView
I have two views that I would like to combine into one. The first
I have two views each of which contain two subviews. Hit detection is working
Imagine you have two views with code like the following: controller_a/a.html.erb <%= content_tag(:div) do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.