0

我在我的应用程序中使用了 admob,但我不断收到以下错误。请记住,我是 android 开发的初学者。

更新了错误的东西 - 不知道我做了什么

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/backgroundtowers" android:orientation="vertical" android:scrollbars="vertical" android:weightSum="1" > <LinearLayout android:id="@+id/MainActivity" android:layout_width="match_parent" android:layout_height="100dp" android:layout_alignParentBottom="true" > </LinearLayout> </RelativeLayout>
<ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >


<LinearLayout android:id="@+id/MainActivity" android:layout_width="match_parent" android:layout_height="100dp" android:layout_alignParentBottom="true" > </LinearLayout>



          <LinearLayout
      android:id="@+id/layoutForScroll"
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:orientation="vertical" >
<LinearLayout
     android:id="@+id/MainActivity"
      android:layout_width="match_parent"
      android:layout_height="100dp"></LinearLayout>

     <TextView
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="23dp"
         android:gravity="center"
         android:text="Welcome To Ride Count"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

        <RelativeLayout
            android:id="@+id/layoutTextViews_one"
            android:layout_width="280dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:background="@drawable/smallbox1" >

     <TextView
         android:id="@+id/txtCountLabel_one"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_marginTop="24dp"
         android:gravity="center"
         android:text="Rides Ridden:"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

    <TextView android:textStyle="bold" android:gravity="center" android:text="0000" android:layout_height="wrap_content"
      android:layout_width="match_parent" android:id="@+id/sum"
       android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000000"  android:layout_marginTop="45dp"></TextView>

   </RelativeLayout>

        <TextView
            android:id="@+id/txtFact"
            android:layout_width="280dp"
            android:layout_height="180dp"
            android:layout_gravity="center"
            android:layout_marginTop="23dp"
            android:background="@drawable/factbox"
            android:gravity="center"
            android:text="Tap For Fact"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textStyle="bold" />

   </LinearLayout>
   </ScrollView>

</LinearLayout>

这是我想要的布局。

错误:

03-31 22:15:57.851: E/Ads(612): Not enough space to show ad! Wants: <480, 75>, Has: <480, 0>

代码主页:

public class HomeActivity extends Activity implements OnClickListener
{
    private TextView sumLabel, factLabel;
    TextView refresh;
    private TextView fact;
    private int sum = 0;
    private SharedPreferences settings;
    private RandomFact facts = new RandomFact();
    private AdView adView;

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        //get label from activity
        sumLabel = (TextView)findViewById(R.id.sum);
        factLabel = (TextView)findViewById(R.id.txtFact);

        refresh = (TextView)findViewById(R.id.sum);
        refresh.setFocusable(true);
        refresh.setOnClickListener(this);
        fact = (TextView)findViewById(R.id.txtFact);
        fact.setOnClickListener(this);
        //set the sum value
        refreshCounter();
        // Create the adView
        adView = new AdView(this, AdSize.BANNER, "ID");

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

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

        // Create an ad request. Check logcat output for the hashed device ID to
        // get test ads on a physical device.
        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        // Start loading the ad in the background.
        adView.loadAd(adRequest);


    }
    /** Called before the activity is destroyed. */
    @Override
    public void onDestroy() {
      // Destroy the AdView.
      if (adView != null) {
        adView.destroy();
      }

      super.onDestroy();
    }

    @Override
    public void onClick(View v) 
    {
        if(v == refresh)
        {
            refreshCounter();   //refresh the individual counters sum
        }
        else if(v == fact)
        {
            factLabel.setText(facts.getAnAnswer());
        }
    }
    //update the  value
    private void refreshCounter()
    {
        sum = 0;
        //get counters value for page one
        settings = getSharedPreferences(CounterOneActivity.PREFS_NAME, 0);
        sum += settings.getInt("counter1", 0);
        sum += settings.getInt("counter2", 0);
        sum += settings.getInt("counter3", 0);
        sum += settings.getInt("counter4", 0);
        sum += settings.getInt("counter5", 0);
        sum += settings.getInt("counter6", 0);
        sum += settings.getInt("counter7", 0);
        sum += settings.getInt("counter8", 0);
        sum += settings.getInt("counter9", 0);
        sum += settings.getInt("counter10", 0);
        sum += settings.getInt("counter11", 0);
        sum += settings.getInt("counter12", 0);
        sum += settings.getInt("counter13", 0);
        sum += settings.getInt("counter14", 0);
        sum += settings.getInt("counter15", 0);
        sum += settings.getInt("counter16", 0);
        sum += settings.getInt("counter17", 0);
        sum += settings.getInt("counter18", 0);
        sum += settings.getInt("counter19", 0);
        sum += settings.getInt("counter20", 0);
        sum += settings.getInt("counter21", 0);
        sum += settings.getInt("counter22", 0);
        sum += settings.getInt("counter23", 0);
        sum += settings.getInt("counter24", 0);
        sum += settings.getInt("counter25", 0);

        //get counters value for page two
        settings = getSharedPreferences(CounterTwoActivity.PREFS_NAME, 0);
        sum += settings.getInt("counter1", 0);
        sum += settings.getInt("counter2", 0);
        sum += settings.getInt("counter3", 0);
        sum += settings.getInt("counter4", 0);
        sum += settings.getInt("counter5", 0);
        sum += settings.getInt("counter6", 0);
        sum += settings.getInt("counter7", 0);
        sum += settings.getInt("counter8", 0);
        sum += settings.getInt("counter9", 0);
        sum += settings.getInt("counter10", 0);
        sum += settings.getInt("counter11", 0);
        sum += settings.getInt("counter12", 0);
        sum += settings.getInt("counter13", 0);
        sum += settings.getInt("counter14", 0);
        sum += settings.getInt("counter15", 0);
        sum += settings.getInt("counter16", 0);
        sum += settings.getInt("counter17", 0);
        sum += settings.getInt("counter18", 0);
        sum += settings.getInt("counter19", 0);
        sum += settings.getInt("counter20", 0);
        sum += settings.getInt("counter21", 0);
        sum += settings.getInt("counter22", 0);
        sum += settings.getInt("counter23", 0);
        sum += settings.getInt("counter24", 0);
        sum += settings.getInt("counter25", 0);
        sum += settings.getInt("counter25", 0);
        sum += settings.getInt("counter26", 0);
        sum += settings.getInt("counter27", 0);
        sum += settings.getInt("counter28", 0);
        sum += settings.getInt("counter29", 0);
        sum += settings.getInt("counter30", 0);
        sum += settings.getInt("counter31", 0);
        sum += settings.getInt("counter32", 0);
        sum += settings.getInt("counter33", 0);
        sum += settings.getInt("counter34", 0);
        sum += settings.getInt("counter35", 0);

        //get counters value for page three
        settings = getSharedPreferences(CounterThreeActivity.PREFS_NAME, 0);
        sum += settings.getInt("counter1", 0);
        sum += settings.getInt("counter2", 0);
        sum += settings.getInt("counter3", 0);
        sum += settings.getInt("counter4", 0);
        sum += settings.getInt("counter5", 0);
        sum += settings.getInt("counter6", 0);
        sum += settings.getInt("counter7", 0);
        sum += settings.getInt("counter8", 0);
        sum += settings.getInt("counter9", 0);
        sum += settings.getInt("counter10", 0);
        sum += settings.getInt("counter11", 0);
        sum += settings.getInt("counter12", 0);
        sum += settings.getInt("counter13", 0);
        sum += settings.getInt("counter14", 0);
        sum += settings.getInt("counter15", 0);
        sum += settings.getInt("counter16", 0);
        sum += settings.getInt("counter17", 0);
        sum += settings.getInt("counter18", 0);
        sum += settings.getInt("counter19", 0);
        sum += settings.getInt("counter20", 0);
        sum += settings.getInt("counter21", 0);
        sum += settings.getInt("counter22", 0);
        sum += settings.getInt("counter23", 0);
        sum += settings.getInt("counter24", 0);
        sum += settings.getInt("counter25", 0);
        sum += settings.getInt("counter25", 0);
        sum += settings.getInt("counter26", 0);
        sum += settings.getInt("counter27", 0);
        sum += settings.getInt("counter28", 0);
        sum += settings.getInt("counter29", 0);
        //get counters value for page four
        settings = getSharedPreferences(CounterFourActivity.PREFS_NAME, 0);
        sum += settings.getInt("counter1", 0);
        sum += settings.getInt("counter2", 0);
        sum += settings.getInt("counter3", 0);
        //set the counter
        sumLabel.setText(String.format("%05d", sum));
    }
}

广告底部 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ad_catalog_layout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/banner_bottom" />
    <TextView android:id="@+id/status"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:text="" />

    <com.google.ads.AdView
        xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/ad"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        googleads:adSize="IAB_MRECT"
        googleads:adUnitId="@string/admob_id" />

</LinearLayout>

主页 xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/MainActivity"
    android:background="@drawable/backgroundtowers"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:weightSum="1" >

      <ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >

  <LinearLayout
      android:id="@+id/layoutForScroll"
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:orientation="vertical" >

     <TextView
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="23dp"
         android:gravity="center"
         android:text="Welcome To Ride Count"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

        <RelativeLayout
            android:id="@+id/layoutTextViews_one"
            android:layout_width="280dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:background="@drawable/smallbox1" >

     <TextView
         android:id="@+id/txtCountLabel_one"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_marginTop="24dp"
         android:gravity="center"
         android:text="Rides Ridden:"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

    <TextView android:textStyle="bold" android:gravity="center" android:text="0000" android:layout_height="wrap_content"
      android:layout_width="match_parent" android:id="@+id/sum"
       android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000000"  android:layout_marginTop="45dp"></TextView>

   </RelativeLayout>

        <TextView
            android:id="@+id/txtFact"
            android:layout_width="280dp"
            android:layout_height="180dp"
            android:layout_gravity="center"
            android:layout_marginTop="23dp"
            android:background="@drawable/factbox"
            android:gravity="center"
            android:text="Tap For Fact"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textStyle="bold" />

   </LinearLayout>
   </ScrollView>

</LinearLayout>
4

2 回答 2

1

这意味着当 Admob 尝试添加他们的广告视图时,他们找不到空间。

您添加scrollViewandroid:layout_width="fill_parent" android:layout_height="fill_parent"这意味着您的所有父布局都被此滚动视图覆盖

尝试添加LinearLayout你的父母LinearLayout

试试这个

`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/backgroundtowers"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:weightSum="1" >

      <ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >

  <LinearLayout
      android:id="@+id/layoutForScroll"
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:orientation="vertical" >
<LinearLayout
     android:id="@+id/MainActivity"
      android:layout_width="match_parent"
      android:layout_height="100dp"></LinearLayout>

     <TextView
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="23dp"
         android:gravity="center"
         android:text="Welcome To Ride Count"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

        <RelativeLayout
            android:id="@+id/layoutTextViews_one"
            android:layout_width="280dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:background="@drawable/smallbox1" >

     <TextView
         android:id="@+id/txtCountLabel_one"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_marginTop="24dp"
         android:gravity="center"
         android:text="Rides Ridden:"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

    <TextView android:textStyle="bold" android:gravity="center" android:text="0000" android:layout_height="wrap_content"
      android:layout_width="match_parent" android:id="@+id/sum"
       android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000000"  android:layout_marginTop="45dp"></TextView>

   </RelativeLayout>

        <TextView
            android:id="@+id/txtFact"
            android:layout_width="280dp"
            android:layout_height="180dp"
            android:layout_gravity="center"
            android:layout_marginTop="23dp"
            android:background="@drawable/factbox"
            android:gravity="center"
            android:text="Tap For Fact"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textStyle="bold" />

   </LinearLayout>
   </ScrollView>

</LinearLayout>`

新版面

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/backgroundtowers"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:weightSum="1" >

      <ScrollView
          android:id="@+id/ScrlView"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_above="@+id/MainActivity"
          android:layout_marginBottom="20dp" >

  <LinearLayout
      android:id="@+id/layoutForScroll"
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:orientation="vertical" >


     <TextView
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="23dp"
         android:gravity="center"
         android:text="Welcome To Ride Count"
         android:textAppearance="?android:attr/textAppearanceLarge"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

        <RelativeLayout
            android:id="@+id/layoutTextViews_one"
            android:layout_width="280dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:background="@drawable/smallbox1" >

     <TextView
         android:id="@+id/txtCountLabel_one"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_marginTop="24dp"
         android:gravity="center"
         android:text="Rides Ridden:"
         android:textColor="#1E90FF"
         android:textStyle="bold" >
</TextView>

    <TextView android:textStyle="bold" android:gravity="center" android:text="0000" android:layout_height="wrap_content"
      android:layout_width="match_parent" android:id="@+id/sum"
       android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000000"  android:layout_marginTop="45dp"></TextView>

   </RelativeLayout>

        <TextView
            android:id="@+id/txtFact"
            android:layout_width="280dp"
            android:layout_height="180dp"
            android:layout_gravity="center"
            android:layout_marginTop="23dp"
            android:background="@drawable/factbox"
            android:gravity="center"
            android:text="Tap For Fact"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textStyle="bold" />

   </LinearLayout>
   </ScrollView>

        <LinearLayout
            android:id="@+id/MainActivity"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="20dp" >

</LinearLayout>
</RelativeLayout>
于 2013-03-31T21:30:27.083 回答
0

尝试将保存广告视图的 LinearLayout 更改为 wrap_content 的高度。

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ad_catalog_layout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
于 2013-03-31T21:20:50.690 回答