Putting an AdMob native ad in a listView

后端 未结 4 1178
时光取名叫无心
时光取名叫无心 2020-12-14 03:00

I\'d like to use the new AdMob native ad functionality in my app. I want to put a native ad within a listView, where every 20th item or so in the list is an ad. Is it possib

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 03:50

    You need to create your own custom list view and custom adapter.

    1. Create a scroll view and a LinearLayout as child
    2. Create your template as xml layout that will handle your content
    3. Create a class that will in Inflat your Layout to The LinearLayout In the ScrollView . Like this :

      private static void CreateIntemEmptty(Context context, ViewGroup view) {
          LayoutInflater inflater = (LayoutInflater) Home.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View child = inflater.inflate(R.layout.empty, null);
          ViewGroup Prnt =(ViewGroup)view.getParent().getParent();
          Prnt.removeViewInLayout((View)view.getParent());
          ViewGroup.LayoutParams p =new ViewGroup.LayoutParams(Prnt.getWidth(),Prnt.getHeight());
          Prnt.addView(child,p);
      }
      

      in this code i create an empty Element and add it

    4. You can add the ADS in the LinearLayout as a child.

提交回复
热议问题