【问题标题】:under which layout banner ad should place?在哪个布局横幅广告应该放置?
【发布时间】:2017-11-06 04:19:47
【问题描述】:

我是新手,正在开发一个测验应用程序。底部有四个按钮。一切正常,但是当我在底部按钮放置横幅广告时无法正常工作。我想,我在错误的布局下放置横幅广告。请检查我的 xml 并建议我横幅广告的正确位置。谢谢。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.myquiz.MainActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<LinearLayout
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_centerHorizontal="true">
</LinearLayout>
<LinearLayout
        android:id="@+id/quizBody"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/header"
        android:orientation="vertical">
<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textColor="#dc143c"
            android:background="@color/questionColor"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="@string/question552"
            android:textAppearance="@style/appearanceBody" />
        <RadioGroup
            android:id="@+id/group552"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp">
            <RadioButton
                android:id="@+id/answer552"

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:text="@string/question552A" />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:text="@string/question552B" />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:text="@string/question552C" />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:text="@string/question552D" />
        </RadioGroup>
</LinearLayout>
<LinearLayout
        android:id="@id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/quizBody"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginRight="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="20dp"
            android:layout_weight="1"
            android:background="@color/result"
            android:onClick="getResults"
            android:text="@string/resultButtonText" />

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="20dp"
            android:layout_weight="1"
            android:background="@color/showanswers"
            android:onClick="correctAnswers"
            android:text="@string/showAnswersButtonText" />

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="20dp"
            android:layout_weight="1"
            android:background="@color/ResetTest"
            android:onClick="resetTest"
            android:text="@string/resetButtonText" />
</LinearLayout>
    <Button
        android:id="@+id/model12expl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#87cefa"
        android:layout_marginBottom="60dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_below="@id/button"
        android:text="View Explanation" />
</RelativeLayout>
</ScrollView>

【问题讨论】:

    标签: android layout admob banner


    【解决方案1】:

    这是一个例子。将您的 Scrollview 放在相对布局中。

        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <com.google.ads.AdView android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            ads:adUnitId="@string/admob_id"
            ads:adSize="BANNER"/>
        <ScrollView android:id="@+id/scrollLayout"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:layout_below="@id/adView">
            <LinearLayout android:layout_height="fill_parent"
                android:layout_width="fill_parent">
                <TextView android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="@string/advancedLayouts_scroll_view_lorem_ipsum"/>
            </LinearLayout>
        </ScrollView>
    </RelativeLayout>
    

    您不希望广告位于 ScrollView 之上,因此您想明确告诉它位于 com.google.ads.AdView 之下。

    【讨论】:

      【解决方案2】:

      将你的代码放在RelativeLayout中

        <?xml version="1.0" encoding="utf-8"?>
          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              tools:context="info.androidhive.admob.MainActivity">
      
             //Place your code here
      
      
      <ScrollView
      android:id="@+id/mainScrollView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      tools:context="com.myquiz.MainActivity">
      <RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">
      <LinearLayout
              android:id="@+id/header"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:layout_centerHorizontal="true">
      </LinearLayout>
      <LinearLayout
              android:id="@+id/quizBody"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/header"
              android:orientation="vertical">
      <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="10dp"
                  android:textColor="#dc143c"
                  android:background="@color/questionColor"
                  android:paddingLeft="10dp"
                  android:paddingRight="10dp"
                  android:text="@string/question552"
                  android:textAppearance="@style/appearanceBody" />
              <RadioGroup
                  android:id="@+id/group552"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="10dp">
                  <RadioButton
                      android:id="@+id/answer552"
      
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingLeft="10dp"
                      android:text="@string/question552A" />
                  <RadioButton
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingLeft="10dp"
                      android:text="@string/question552B" />
                  <RadioButton
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingLeft="10dp"
                      android:text="@string/question552C" />
                  <RadioButton
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:paddingLeft="10dp"
                      android:text="@string/question552D" />
              </RadioGroup>
      </LinearLayout>
      <LinearLayout
              android:id="@id/button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/quizBody"
              android:orientation="horizontal">
      
              <Button
                  android:id="@+id/button2"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="20dp"
                  android:layout_marginRight="5dp"
                  android:layout_marginLeft="5dp"
                  android:layout_marginTop="20dp"
                  android:layout_weight="1"
                  android:background="@color/result"
                  android:onClick="getResults"
                  android:text="@string/resultButtonText" />
      
              <Button
                  android:id="@+id/button3"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="20dp"
                  android:layout_marginRight="5dp"
                  android:layout_marginTop="20dp"
                  android:layout_weight="1"
                  android:background="@color/showanswers"
                  android:onClick="correctAnswers"
                  android:text="@string/showAnswersButtonText" />
      
              <Button
                  android:id="@+id/button1"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="20dp"
                  android:layout_marginRight="5dp"
                  android:layout_marginTop="20dp"
                  android:layout_weight="1"
                  android:background="@color/ResetTest"
                  android:onClick="resetTest"
                  android:text="@string/resetButtonText" />
      </LinearLayout>
          <Button
              android:id="@+id/model12expl"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="#87cefa"
              android:layout_marginBottom="60dp"
              android:layout_marginLeft="5dp"
              android:layout_marginRight="5dp"
              android:layout_below="@id/button"
              android:text="View Explanation" />
      </RelativeLayout>
      </ScrollView>
      //end
              <com.google.android.gms.ads.AdView
                  android:id="@+id/adView"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true"
                  android:layout_alignParentBottom="true"
                  ads:adSize="BANNER"
                  ads:adUnitId="@string/banner_home_footer">
              </com.google.android.gms.ads.AdView>
          </RelativeLayout>
      

      【讨论】:

      • 在我的 XML 中的位置。
      • 将您的 xml 代码放在 com.google.android.gms.ads.AdView 上方
      • 我的 XML 以滚动视图开头
      猜你喜欢
      • 1970-01-01
      • 2020-06-24
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2021-02-26
      • 2022-08-14
      相关资源
      最近更新 更多