1

Hello I am trying to make an app that shows native ads to users.

I wrote the xml code and java code.

Everything works fine except there is a space between to things (Image and AD Sign)

Here you can see: [1]: https://i.stack.imgur.com/qVhUz.jpg

I dont want that extra space please help:

btw here is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.google.android.gms.ads.nativead.MediaView
                android:id="@+id/native_ad_media"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                ></com.google.android.gms.ads.nativead.MediaView>

            <TextView
                android:id="@+id/tv_list_tile_native_ad_attribution_small"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#CDCFD3"
                android:text="AD"
                android:textColor="#FFFFFF"
                android:textSize="12sp" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:orientation="horizontal"
                android:paddingLeft="16dp"
                android:paddingRight="16dp">
                <ImageView
                    android:id="@+id/native_ad_icon"
                    android:layout_width="60dp"
                    android:layout_height="60dp"></ImageView>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/native_ad_headline"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:ellipsize="end"
                        android:lines="1"
                        android:maxLines="1"
                        android:textColor="#000000"
                        android:textSize="16sp"
                        android:layout_marginLeft="8dp"
                        android:layout_marginTop="3dp"
                        tools:text="Headline" />

                    <TextView
                        android:id="@+id/native_ad_body"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:ellipsize="end"
                        android:lines="1"
                        android:maxLines="1"
                        android:layout_marginLeft="8dp"
                        android:textColor="#828282"
                        android:textSize="14sp"
                        tools:text="body" />
                </LinearLayout>
            </LinearLayout>

            <Button
                android:id="@+id/native_ad_callToActionButton"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginTop="8dp"
                android:background="@drawable/bg"
                android:ellipsize="end"
                android:lines="1"
                android:maxLines="1"
                android:text="Avaa"
                android:textColor="#FFFFFF"
                android:textSize="28sp" />


        </LinearLayout>


    </FrameLayout>
</com.google.android.gms.ads.nativead.NativeAdView>

please help i am a beginner.

Fatih Koc
  • 11
  • 1
  • This space can be avoided dynamically with java code by using setOnHierarchyChangeListener to your MediaView. Please check answers here. Try changing bounds for the image and scaling to centerCrop. https://stackoverflow.com/questions/52098086/google-ads-mediaview-not-correctly-resizing-height-to-wrap-content-when-displayi – Rajasekhar Nov 29 '21 at 18:55
  • thanks. Appreciate your help! – Fatih Koc Dec 18 '21 at 22:46

0 Answers0