【问题标题】:adMob banner covers text view when soft keyboard pops up弹出软键盘时,adMob 横幅会覆盖文本视图
【发布时间】:2011-09-07 23:09:19
【问题描述】:

我一直无法阻止 adMob 横幅沿软键盘滚动并覆盖我的文本视图....

这是我想要在 Android 中实现的目标的链接:http://bit.ly/myfoodcalc

我知道我的布局有点复杂,嵌套视图太多(可能)等等。

我尝试在 Manifest 上更改内容但没有成功。

为了让您更好地理解这里是子伪 XML(以及后面的完整 XML)...

 <ScrollView>
      <Linear layout>
            <ImageView>
            <TableView>
                  <Several rows with a Edit Text widget>
            </TableView>
            </ImageView>
      </LinearLayout>
  </ScrollView>

  <FrameLayout>
       <ImageView>
  </FrameLayout>

这是我完整的 XML

<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android" 
                    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent" 
                    android:id="@+id/relativeLayout"
                    android:background="@drawable/backgroundwithtext">

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

        <LinearLayout   android:id="@+id/linearLayout1" 
                        android:layout_width="fill_parent" 
                        android:layout_height="fill_parent" 
                        android:orientation="vertical" 
                        android:gravity="center_horizontal">

            <ImageView  android:id="@+id/imageView1" 
                        android:layout_width="wrap_content" 
                        android:src="@drawable/icon" 
                        android:layout_height="wrap_content"></ImageView>

            <TableLayout    android:id="@+id/tableLayout1" 
                            android:layout_height="wrap_content" 
                            android:layout_width="wrap_content" 
                            android:background="@drawable/backgroundsmallobj">

                <TableRow   android:id="@+id/tableRow1" 
                            android:layout_width="wrap_content" 
                            android:layout_height="wrap_content">

                    <TextView   android:text="TITLE" 
                                android:layout_width="wrap_content" 
                                android:layout_height="wrap_content" 
                                android:id="@+id/textView1">
                    </TextView>

                </TableRow>

                <TableRow   android:id="@+id/tableRow2" 
                            android:layout_width="wrap_content" 
                            android:layout_height="wrap_content">

                    <EditText   android:text="EditText" 
                                android:maxLines="1" 
                                android:id="@+id/editText2" 
                                android:layout_width="wrap_content"     
                                android:layout_height="wrap_content" 
                                android:imeOptions="actionNext">
                    </EditText>

                </TableRow>

                <TableRow   android:id="@+id/tableRow3" 
                            android:layout_width="wrap_content" 
                            android:layout_height="wrap_content">

                    <EditText   android:text="EditText" 
                                android:maxLines="1" 
                                android:id="@+id/editText3" 
                                android:layout_width="wrap_content" 
                                android:layout_height="wrap_content"
                                android:imeOptions="actionNext">
                    </EditText>

                </TableRow>

                <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height="wrap_content">

                    <EditText   android:text="EditText" 
                                android:maxLines="1" 
                                android:id="@+id/editText4" 
                                android:layout_width="wrap_content" 
                                android:layout_height="wrap_content" 
                                android:imeOptions="actionNext">
                    </EditText>

                </TableRow>

                <TableRow   android:id="@+id/tableRow5" 
                            android:layout_width="wrap_content" 
                            android:layout_height="wrap_content">

                    <EditText   android:text="EditText"
                                android:maxLines="1" 
                                android:id="@+id/editText5" 
                                android:layout_width="wrap_content" 
                                android:layout_height="wrap_content" 
                                android:imeOptions="actionNext">
                    </EditText>

                </TableRow>

                <TableRow android:id="@+id/tableRow6" android:layout_width="wrap_content" android:layout_height="wrap_content">
                    <EditText android:text="EditText" android:maxLines="1" android:id="@+id/editText6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:imeOptions="actionDone"></EditText>
                </TableRow>

                <TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content">
                    <Button android:id="@+id/button1" android:layout_height="wrap_content" android:text="Button" android:layout_width="wrap_content"></Button>
                </TableRow>


            </TableLayout>

        </LinearLayout>

    </ScrollView>

    <FrameLayout    android:id="@+id/frameLayout1" 
                    android:layout_height="wrap_content" 
                    android:layout_alignParentBottom="true" 
                    android:layout_width="fill_parent">

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

    </FrameLayout>

</RelativeLayout>

【问题讨论】:

    标签: android layout keyboard android-edittext admob


    【解决方案1】:

    您可以更改键盘在广告上显示时的行为方式。进入您的 AndroidManifest.xml 并在带有 AdMob 横幅的活动标记中添加此属性。

    android:windowSoftInputMode="adjustPan"
    

    这将防止广告跳到键盘上方并隐藏输入。相反,它们将出现在键盘后面(隐藏)。我不知道这是否违反 AdMob 政策,我只是提供一个解决方案。

    【讨论】:

      【解决方案2】:

      我尝试设置 android:windowSoftInputMode="adjustPan"。 它隐藏了 adMob 横幅也隐藏了 EdiText。 所以我找到的解决方案是在键盘打开时隐藏 adMob 横幅。 我学会了如何检测键盘是否打开here。 这是我的解决方案:

      final View activityRootView = findViewById(R.id.sample_main_layout);
                  activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                      @Override
                      public void onGlobalLayout() {
                          int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
                          if (heightDiff > Support.dpToPx(MainActivity.this, 200)) { // if more than 200 dp, it's probably a keyboard...
                              mAdView.setVisibility(View.GONE);
                          }
                          else{
                              mAdView.setVisibility(View.VISIBLE);
                          }
                       }
                  });
      

      【讨论】:

        【解决方案3】:

        将此添加到您的活动清单中 android:windowSoftInputMode="stateVisible|adjustPan"

        【讨论】:

          【解决方案4】:

          这对您来说可能不是理想的解决方案,但我发现它对我的用户来说是最好的。当显示键盘时,它覆盖了我的 WebView 中的按钮和文本,从而导致用户体验不佳。为了解决这个问题,我将我的 AdView 高度设置为横幅广告的高度,在我的情况下为 50dp,并将 AdView 布局设置为低于 WebView。最后,我将 WebView 高度设置为 wrap_content。当键盘可见时,广告会因为空间不足而暂时移除,当键盘隐藏时,广告会再次显示。希望这可以帮助。

          <WebView
              android:id="@+id/webUI"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_alignParentTop="true" />
          
          <com.google.ads.AdView android:id="@+id/adView"
              android:layout_width="wrap_content"
              android:layout_height="50dp"
              android:layout_below="@+id/webUI" />
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-09-15
            • 2015-11-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-10-30
            • 1970-01-01
            相关资源
            最近更新 更多