Skip to content

Commit

Permalink
refactor(admob): replace RelativeLayout with ConstraintLayout (fireba…
Browse files Browse the repository at this point in the history
  • Loading branch information
thatfiredev authored Dec 7, 2020
1 parent b3db77e commit 3b639ec
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
35 changes: 24 additions & 11 deletions admob/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<!-- [SNIPPET define_ad_layout]
Define the namespace and AdView layout that will show the banner.
[START define_ad_layout] -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".java.MainActivity">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/firebase_lockup_400"/>
android:layout_marginTop="16dp"
android:src="@drawable/firebase_lockup_400"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/loadInterstitialButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/interstitial_button_text" />
android:text="@string/interstitial_button_text"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
Expand All @@ -32,6 +35,16 @@ Define the namespace and AdView layout that will show the banner.
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
ads:adUnitId="@string/banner_ad_unit_id"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />

</RelativeLayout><!-- [END define_ad_layout] -->
</androidx.constraintlayout.widget.ConstraintLayout><!-- [END define_ad_layout] -->
33 changes: 22 additions & 11 deletions admob/app/src/main/res/layout/second_activity.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:viewBindingIgnore="true"
tools:context="com.google.samples.quickstart.admobexample.java.SecondActivity">
tools:context="com.google.samples.quickstart.admobexample.java.SecondActivity"
tools:viewBindingIgnore="true">

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/firebase_lockup_400" />
android:src="@drawable/firebase_lockup_400"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/icon"
android:layout_centerHorizontal="true"
android:text="@string/second_activity_content" />
android:layout_gravity="center_horizontal"
android:text="@string/second_activity_content"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="@+id/icon"
app:layout_constraintStart_toStartOf="@+id/icon"
app:layout_constraintTop_toBottomOf="@+id/icon" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 3b639ec

Please sign in to comment.