1

I'm adding AdMob to my application. Apparently I need to add the following layout snippet to each one of my layouts:

 <LinearLayout
     android:id="@+id/linearLayout"
     android:orientation="vertical"
     android:layout_below="@+id/button2"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content" />

However, I'd rather add the above snippet dynamically, instead of copy-pasting it into each layout.

What I am having trouble with is translating the following snippet:

android:layout_below="@+id/button2"

into Java code.

Anders R. Bystrup
  • 15,324
  • 10
  • 61
  • 54
MDP
  • 3,957
  • 18
  • 58
  • 109

1 Answers1

1

You have two options (at least):

  1. Remove on the XML the android:layout_below="@+id/button2"and add this property on code, like says on this question: How to lay out Views in RelativeLayout programmatically?
  2. The other option is create an xml layout with only the code that you post on your question, without the android:layout_below="@+id/button2". Then in each layout that you want to use this, use the include element: http://developer.android.com/training/improving-layouts/reusing-layouts.html

Hope it helps.

Community
  • 1
  • 1
sabadow
  • 5,064
  • 3
  • 33
  • 51