0

我正在尝试将 admob 添加为 header.but 有错误。是否可以在列表视图中添加标题。

admob.xml

          <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="AD_UNIT_ID"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"/>

列表.xml

<?xml version="1.0" encoding="utf-8"?>

android:layout_height="wrap_content"

  android:background="@drawable/selector"

      android:padding="5dp" >

<ImageView
    android:id="@+id/logo"
    android:layout_width="0dp"
    android:layout_height="45dp"
    android:layout_marginLeft="5dp"
      android:duplicateParentState="true"

    android:layout_weight="10"
    android:src="@drawable/play" />

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="45dp"
    android:layout_weight="40.00"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/Tittle"
        android:layout_width="match_parent"
        android:layout_height="27dp"
        android:text="@+id/Tittle"
          android:duplicateParentState="true"
        android:layout_gravity="center_horizontal"
        android:textSize="18sp" >

    </TextView>

       <TextView
           android:id="@+id/Descriprion"
           android:layout_width="match_parent"
           android:layout_height="18dp"
             android:duplicateParentState="true"
           android:text="@+id/Descriprion"
           android:layout_gravity="center_horizontal"


           android:textSize="16sp" >

    </TextView>
</LinearLayout>


<ImageView
    android:id="@+id/options"
    android:layout_width="0dp"
    android:layout_height="45dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="5dp"
    android:layout_weight="9.52"
  android:duplicateParentState="false"
android:background="@drawable/selector"
    android:src="@drawable/options" />

组合.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <include layout="@layout/admob"/>

    <include layout="@layout/list"/>            
       </LinearLayout>

并在构造函数中

     public MobileArrayAdapter(final Context context, String[] values, MediaPlayer mp2) {
    super(context, R.layout.combined, values);
      inflater =  (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.context = context;
    this.values = values;

并在 getview public View getView(int position, View rowView, ViewGroup parent) {

         ViewHolder holder =null;
    if (rowView == null) {

         rowView = inflater.inflate(R.layout.list_mobile, null);
        holder  = new ViewHolder();
         holder.text = (TextView) rowView.findViewById(R.id.Tittle);
         holder.descrip=(TextView)rowView.findViewById(R.id.Descriprion);
       holder.  imageView= (ImageView) rowView
                 .findViewById(R.id.logo);
       holder.options = (ImageView)rowView.findViewById(R.id.options)






         rowView.setTag(holder);
    }else {
        holder=   (ViewHolder) rowView.getTag();


        AdView adView = new AdView((Activity) getContext(), AdSize.BANNER, "a1524d14f8dfc1b" );

        AdRequest adrequest = new AdRequest();

       adrequest.addTestDevice(AdRequest.TEST_EMULATOR);

        // Lookup your LinearLayout assuming it's been given
        // the attribute android:id="@+id/mainLayout"
        LinearLayout layout1 = (LinearLayout)findViewById(R.id.webView1);

        // Add the adView to it
        layout1.addView(adView);



        // Add the adView to it
        layout1.addView(adView);
        adView.loadAd(adrequest);
     }



    holder. imageView.setTag(position);
    holder.options.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mQuickAction.show(arg0); 

        }
    });

错误 日志猫

4

2 回答 2

0

您好,您可以按照此(https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#android)一步一步的过程在android项目中添加admob。

于 2013-10-03T08:11:04.717 回答
0

试试这个,在你的 combine.xml 添加布局宽度和高度。

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/home_root"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

<include layout="@layout/admob"
  android:layout_width="fill_parent"
 android:layout_height="wrap_content"/>

<include layout="@layout/list"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"/>            
   </LinearLayout>
于 2013-10-03T08:06:02.667 回答