Please I need your help. I'm truggling to implement google Admob Banner in my app but it's male functioning. When I put the admob code in the activity_main.xml, in the relative layout block, my content doesn't appear but ad is displayed and when I remove the banner code from the layout, the app works fine.
Here is the code:
activity_main:
and the MainActivity.java:
Thanks in advance!!!
Here is the code:
activity_main:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:eek:rientation="vertical"
tools:context="com.myapp.hello.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/topColor">
<ImageView
android:id="@+id/app_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="3dp"
android:background="@drawable/back_img"
android:src="@drawable/in_app_icon" />
<TextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/app_icon"
android:text="@string/app_name"
android:textColor="#000"
android:textSize="24dp" />
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_icon"
android:layout_gravity="center_vertical"
android:layout_marginTop="20dp"
android:paddingBottom="8dp"
app:pstsDividerColor="@color/topColor"
app:pstsIndicatorHeight="4dp"
app:pstsTabPaddingLeftRight="10dp"
/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom"
android:layout_below="@+id/tabs"
android:cacheColorHint="#00000000"
android:scrollbars="none"
/>
</LinearLayout>
and the MainActivity.java:
Java:
public class MainActivity extends FragmentActivity implements ViewPager.OnPageChangeListener { private AdView mAdView;
ViewPager pager;
PagerSlidingTabStrip tabs;
private int previousPage = 0;
List<Fragment> fragment;
TextView app_name;
private int[] imageResId = { R.drawable.selectore_tab1, R.drawable.01, R.drawable.02 };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.topbar));
}
pager=(ViewPager)findViewById(R.id.pager);
tabs = (PagerSlidingTabStrip)findViewById(R.id.tabs);
tabs.setShouldExpand(true);
LinearLayout view = (LinearLayout) tabs.getChildAt(0);
app_name=(TextView)findViewById(R.id.app_name) ;
Typeface face = Typeface.createFromAsset(getAssets(),
"fonts/Android Insomnia Regular.ttf");
app_name.setTypeface(face);
tabs.setOnPageChangeListener(this);
pager = (ViewPager) findViewById(R.id.pager);
//adapter = new MyPagerAdapter(getSupportFragmentManager());
fragment = new ArrayList<Fragment>();
fragment.add(new Fragment1());
fragment.add(new Fragment2());
fragment.add(new Fragment3());
// pager.setAdapter(new CustomPagerAdapter(getSupportFragmentManager(),fragment));
pager.setAdapter(new MainAdapter(getSupportFragmentManager(),imageResId));
tabs.setViewPager(pager);
tabs.setIndicatorColor(Color.parseColor("#000000"));
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
//
mAdView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//
}
Thanks in advance!!!