Android: примем нативный дизайн рекламы - PullRequest
0 голосов
/ 21 апреля 2020

Я хотел бы, чтобы значок информации на изображении был go на странице xml, которую я создал.

android: id = "@ + id / ao_native_ad_choices"

Но я не смог этого сделать, чем я могу вам помочь?

Если вы посмотрите на изображение, вы поймете меня лучше. Я показал это на изображении. Я новичок в android, жду вашей помощи.

Я хочу, чтобы она закрывалась при нажатии кнопки закрытия.

android: id = "@ + id / close_icon_image"

введите описание изображения здесь

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

   <RelativeLayout
       android:id="@+id/native_outer_view"
       android:layout_width="@dimen/native_ad_width"
       android:layout_height="@dimen/native_ad_height"
       android:layout_gravity="center_horizontal"
       android:background="@drawable/bg_native_ad"
       android:clickable="true">

       <ImageView
           android:id="@+id/ad_icon"
           android:layout_width="64.0dip"
           android:layout_height="64.0dip"
           android:layout_alignParentStart="true"
           android:layout_alignParentLeft="true"
           android:layout_alignParentTop="true"
           android:layout_margin="10.0dip"
           android:background="@null"
           android:contentDescription="@null" />

       <TextView
           android:id="@+id/ad_headline"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentTop="true"
           android:layout_marginTop="10.0dip"
           android:layout_toStartOf="@+id/close_icon_image"
           android:layout_toLeftOf="@+id/close_icon_image"
           android:layout_toEndOf="@+id/ad_icon"
           android:layout_toRightOf="@+id/ad_icon"
           android:maxLines="2"
           android:textColor="@android:color/white"
           android:textSize="18.0dip" />

       <LinearLayout
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_below="@+id/ad_headline"
           android:layout_toStartOf="@+id/close_icon_image"
           android:layout_toLeftOf="@+id/close_icon_image"
           android:layout_toEndOf="@+id/ad_icon"
           android:layout_toRightOf="@+id/ad_icon"
           android:gravity="center_vertical"
           android:orientation="horizontal">

           <TextView
               android:id="@+id/ad_advertiser"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="@string/sponsored_label"
               android:textAppearance="@style/TextAppearance.AppCompat.Small"
               android:textSize="14.0dip" />

           <RelativeLayout
               android:id="@+id/ao_native_ad_choices"
               android:layout_width="25.0dip"
               android:layout_height="25.0dip"
               android:layout_marginLeft="8.0dip">

               <ImageView
                   android:id="@+id/ao_native_ad_daa_icon_image"
                   android:layout_width="25.0dip"
                   android:layout_height="25.0dip"
                   android:background="@null" />
           </RelativeLayout>

           <RatingBar
               android:id="@+id/ad_rating"
               style="?android:attr/ratingBarStyleSmall"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:isIndicator="true"
               android:numStars="5"
               android:stepSize="0.5" />
       </LinearLayout>

       <TextView
           android:id="@+id/ad_body"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_above="@+id/ao_native_main_image_container"
           android:layout_alignParentStart="true"
           android:layout_alignParentLeft="true"
           android:layout_marginStart="10.0dip"
           android:layout_marginLeft="10.0dip"
           android:layout_marginEnd="10.0dip"
           android:layout_marginRight="10.0dip"
           android:maxLines="2"
           android:textColor="@android:color/white"
           android:textSize="13.0dip" />

       <FrameLayout
           android:id="@+id/ao_native_main_image_container"
           android:layout_width="@dimen/native_main_image_width"
           android:layout_height="@dimen/native_main_image_height"
           android:layout_above="@+id/ad_call_to_action"
           android:layout_marginStart="5.0dip"
           android:layout_marginLeft="5.0dip"
           android:layout_marginTop="12.0dip"
           android:layout_marginEnd="5.0dip"
           android:layout_marginRight="5.0dip">

           <com.google.android.gms.ads.formats.MediaView
               android:id="@+id/ad_media"
               android:layout_width="@dimen/native_main_image_width"
               android:layout_height="@dimen/native_main_image_height"
               android:layout_gravity="center"
               android:background="@null" />
       </FrameLayout>

       <TextView
           android:id="@+id/ad_price"
           style="@style/Button.Ad"
           android:layout_width="wrap_content"
           android:layout_height="@dimen/native_ad_button_size"
           android:layout_alignParentBottom="true"
           android:layout_marginLeft="20.0dip"
           android:layout_marginTop="16.0dip"
           android:layout_marginBottom="16.0dip"
           android:maxLines="1"
           android:paddingStart="16.0dip"
           android:paddingLeft="16.0dip"
           android:paddingEnd="16.0dip"
           android:paddingRight="16.0dip"
           android:textSize="18.0dip" />

       <TextView
           android:id="@+id/ad_store"
           style="@style/Button.Ad"
           android:layout_width="wrap_content"
           android:layout_height="@dimen/native_ad_button_size"
           android:layout_alignParentBottom="true"
           android:layout_centerHorizontal="true"
           android:layout_marginLeft="20.0dip"
           android:layout_marginTop="16.0dip"
           android:layout_marginBottom="16.0dip"
           android:layout_toEndOf="@+id/ad_price"
           android:maxLines="1"
           android:paddingStart="16.0dip"
           android:paddingLeft="16.0dip"
           android:paddingEnd="16.0dip"
           android:paddingRight="16.0dip"
           android:textSize="18.0dip" />

       <Button
           android:id="@+id/ad_call_to_action"
           style="@style/Button.Ad"
           android:layout_width="wrap_content"
           android:layout_height="@dimen/native_ad_button_size"
           android:layout_alignParentBottom="true"
           android:layout_centerHorizontal="true"
           android:layout_marginLeft="20.0dip"
           android:layout_marginTop="16.0dip"
           android:layout_marginBottom="16.0dip"
           android:layout_toEndOf="@+id/ad_store"
           android:maxLines="1"
           android:paddingStart="16.0dip"
           android:paddingLeft="16.0dip"
           android:paddingEnd="16.0dip"
           android:paddingRight="16.0dip"
           android:textSize="18.0dip" />


       <ImageView
           android:id="@+id/close_icon_image"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentTop="true"
           android:layout_alignParentEnd="true"
           android:layout_alignParentRight="true"
           android:layout_margin="20.0dip"
           android:contentDescription="@null"
           android:src="@drawable/bg_btn_close" />
   </RelativeLayout>
</com.google.android.gms.ads.formats.UnifiedNativeAdView>

AdLoader adLoader = new AdLoader.Builder(getContext(), "ca-app-pub-3940256099942544/2247696110")
                .forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                    @Override
                    public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                        //the native ad will be available inside this method  (unifiedNativeAd)

                        UnifiedNativeAdView unifiedNativeAdView = (UnifiedNativeAdView) getLayoutInflater().inflate(R.layout.native_ad_layout, null);
                        mapUnifiedNativeAdToLayout(unifiedNativeAd, unifiedNativeAdView);

                        FrameLayout nativeAdLayout = view.findViewById(R.id.id_native_ad);
                        nativeAdLayout.removeAllViews();
                        nativeAdLayout.addView(unifiedNativeAdView);
                    }
                })
                .build();
        adLoader.loadAd(new AdRequest.Builder().build());


public void mapUnifiedNativeAdToLayout(UnifiedNativeAd adFromGoogle, UnifiedNativeAdView myAdView) {
        MediaView mediaView = myAdView.findViewById(R.id.ad_media);
        myAdView.setMediaView(mediaView);

        myAdView.setHeadlineView(myAdView.findViewById(R.id.ad_headline));
        myAdView.setBodyView(myAdView.findViewById(R.id.ad_body));
        myAdView.setCallToActionView(myAdView.findViewById(R.id.ad_call_to_action));
        myAdView.setIconView(myAdView.findViewById(R.id.ad_icon));
        myAdView.setPriceView(myAdView.findViewById(R.id.ad_price));
        myAdView.setStarRatingView(myAdView.findViewById(R.id.ad_rating));
        myAdView.setStoreView(myAdView.findViewById(R.id.ad_store));
        myAdView.setAdvertiserView(myAdView.findViewById(R.id.ad_advertiser));



        ((TextView) myAdView.getHeadlineView()).setText(adFromGoogle.getHeadline());

        if (adFromGoogle.getBody() == null) {
            myAdView.getBodyView().setVisibility(View.GONE);
        } else {
            ((TextView) myAdView.getBodyView()).setText(adFromGoogle.getBody());
        }

        if (adFromGoogle.getCallToAction() == null) {
            myAdView.getCallToActionView().setVisibility(View.GONE);
        } else {
            ((Button) myAdView.getCallToActionView()).setText(adFromGoogle.getCallToAction());
        }

        if (adFromGoogle.getIcon() == null) {
            myAdView.getIconView().setVisibility(View.GONE);
        } else {
            ((ImageView) myAdView.getIconView()).setImageDrawable(adFromGoogle.getIcon().getDrawable());
        }


        if (adFromGoogle.getPrice() == null) {
            myAdView.getPriceView().setVisibility(View.GONE);
        } else {
            ((TextView) myAdView.getPriceView()).setText(adFromGoogle.getPrice());
        }

        if (adFromGoogle.getStarRating() == null) {
            myAdView.getStarRatingView().setVisibility(View.GONE);
        } else {
            ((RatingBar) myAdView.getStarRatingView()).setRating(adFromGoogle.getStarRating().floatValue());
        }

        if (adFromGoogle.getStore() == null) {
            myAdView.getStoreView().setVisibility(View.GONE);
        } else {
            ((TextView) myAdView.getStoreView()).setText(adFromGoogle.getStore());
        }

        if (adFromGoogle.getAdvertiser() == null) {
            myAdView.getAdvertiserView().setVisibility(View.GONE);
        } else {
            ((TextView) myAdView.getAdvertiserView()).setText(adFromGoogle.getAdvertiser());
        }
        myAdView.setNativeAd(adFromGoogle);
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...