1

I'm in a similar situation to this guy: Implementing Admob banner when setContentView() is used for the Surfaceview

My "sGame" creates a landscape view game that I want with an admob ad put on top.

I think the answer will work, but I'm not sure which LayoutParams to import for the "layout.setLayoutParams".

When I hit Alt+Enter on the LayoutParams, I get the following options:

import android.view.ViewGroup.LayoutParams;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.FrameLayout.LayoutParams;
import android.widget.GalleryLayout.LayoutParams;
import android.support.v7.widget.LinearLayoutCompat.LayoutParams;
//... quite a few more options

2 Answers2

0

It depends on the type of layout.

From the link, it's a RelativeLayout, so you need import android.widget.RelativeLayout.LayoutParams.

Hong Duan
  • 4,234
  • 2
  • 27
  • 50
0

Different layout managers use different layout parameters. It's very obvious: RelativeLayout uses RelativeLayout.LayoutParams, LinearLayout uses LinearLayout.LayoutParams etc.

That means, you need to use RelativeLayout.LayoutParams:

import android.widget.RelativeLayout.LayoutParams;

Because in the link you mentioned, the answer tells you to use RelativeLayout.

And now, let me give you some extra information. What if you use the wrong params? An InvalidCastException is thrown. When you encounter that exception, you would probably know what is wrong. You use the wrong type of Params. And Android is trying to cast that type of Params to the correct type!

Sweeper
  • 213,210
  • 22
  • 193
  • 313