Position button on top of ad

Asked

Viewed 88 times

2

Hello, I would like to know how to put a close ad button in the corner of the screen, on top of the ad.

I even tried here more takes space from the webview above and is not transparent the part, for example: The button is in the corner but takes space from webview and the background is not transparent.

Take the example: Como eu quero See that on the X there’s blue on the left, I didn’t want that, just the X there where it really is, but without that blue part.

Code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adsContainer"
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="com.xxxxxxxxxx.android.MainActivity"
android:padding="0dp"
android:orientation="vertical"
android:weightSum="1"
android:background="#2c3e50">
<FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="invisible"
        android:indeterminate="false" />
    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webview"
        android:visibility="invisible"/>
</FrameLayout>
<LinearLayout
    android:id="@+id/frameAds"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation=“vertical”>
<Button
        android:id="@+id/closeAd"
        android:background="@android:drawable/ic_menu_close_clear_cancel"
        android:layout_gravity="end"
        android:layout_width="25dp"
        android:layout_height="25dp"
        ads:backgroundTint="@android:drawable/screen_background_dark_transparent"
        android:visibility="visible" />
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/ID_ANUNCIO_BANNER"/>          
    </LinearLayout>
     </LinearLayout>

Can someone help me?

  • It is not clear what you want. If possible put a picture of how you are and how you want it to appear.

  • I put an example image. I hope you understand

1 answer

1


Use relative layout to group the close bottom and the ad. When the user clicks close you change the relative layout to GONE visibility.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adsContainer"
    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="com.xxxxxxxxxx.android.MainActivity"
    android:padding="0dp"
    android:orientation="vertical"
    android:weightSum="1"
    android:background="#2c3e50">
    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <ProgressBar
            style="?android:attr/progressBarStyleLarge"
            android:id="@+id/progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="invisible"
            android:indeterminate="false" />
        <WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/webview"
            android:visibility="invisible"/>
    </FrameLayout>
    <LinearLayout
        android:id="@+id/frameAds"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation=“vertical”>
    <Button
            android:id="@+id/closeAd"
            android:background="@android:drawable/ic_menu_close_clear_cancel"
            android:layout_gravity="end"
            android:layout_width="25dp"
            android:layout_height="25dp"
            ads:backgroundTint="@android:drawable/screen_background_dark_transparent"
            android:visibility="visible" />
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/ID_ANUNCIO_BANNER"/>          
    </LinearLayout>
</LinearLayout>
  • Thanks for the reply! But I can not understand so, I’m still novice in the area of Android!

  • I forgot to come here in the afternoon! Tomorrow I will test and put the result! Thank you!

  • 1

    I adjusted the answer based on the image you posted.

  • Fix an error and edited your reply! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.