2011-04-19 176 views
0

我刚刚将AdWhirl集成到我的应用程序中。我将AdWhirl视图设置为显示在我主要活动布局的底部。我的主布局上有几个EditText框,当应用第一次启动时,单击文本框通常会显示软键盘。但是,当我转到其他活动并返回到我的主要活动时,然后单击EditText软键盘弹出,顶部的AdWhirl视图弹出,覆盖了我的EditText框。我一直在为此挣扎好几天。任何帮助,将不胜感激。在软键盘上显示Adview

我有我的清单中定义的所有活动android:windowSoftInputMode =“adjustPan”。

这里是我的main.xml布局:

<RelativeLayout android:id="@+id/RelativeLayout01" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<ImageView android:id="@+id/ImageView02" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:background="@drawable/other_bg_small" android:layout_weight="1"/> 

<ImageView android:id="@+id/ImageView01" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:background="@drawable/banner" android:layout_alignParentTop="true" 
    android:paddingBottom="30dip"/> 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:stretchColumns="1" android:gravity="center"  android:id="@+id/table01" 
    android:layout_below="@id/ImageView01" > 

    ... Table stuff 
</TableLayout> 

<LinearLayout android:layout_width="fill_parent" 
    android:id="@+id/ad_layout" android:layout_height="wrap_content" 
    android:gravity="bottom" android:layout_alignParentBottom="true" 
    android:layout_alignBottom="@+id/RelativeLayout01" android:layout_weight="1"> 

    <com.adwhirl.AdWhirlLayout android:id="@+id/adwhirl_layout" 
     android:layout_width="fill_parent" android:layout_height="wrap_content"/> 

</LinearLayout> 

</RelativeLayout> 

回答

2

尝试onFocusChangeListener设置为您的EditText框。当他们获得焦点时,将AdWhirl视图的可见性设置为View.INVISIBLE,以便它不会阻塞文本框,然后在焦点丢失后将其设置为可见。

final AdWhirl ad = (AdWhirl)findViewById(R.id.adwhirlAd); 
     EditText et = (EditText)findViewById(R.id.editTextBox); 
     et.setOnFocusChangeListener(new OnFocusChangeListener() { 

      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 

       ad.setVisibility(hasFocus ? View.INVISIBLE : View.VISIBLE); 

      } 
     }); 
+0

这似乎帮助,唯一的问题是,我有2盒的EditText,如果我实现你的每一个解决方案,广告从来没有显示... – 2011-04-19 06:10:05

+5

尝试以编程方式设置它使用getWindow()。setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);在你的onCreate。 – Joe 2011-04-19 07:00:06

+0

我认为这工作!谢谢!我想知道为什么清单属性没有粘... – 2011-04-19 14:12:18

0

我试着设置android:windowSoftInputMode =“adjustPan”。 它隐藏了adMob横幅但是也是EdiText。 我也试过接受的答案,但edittext可以获得焦点,而不需要打开键盘。 因此我找到的解决方案是在键盘打开时隐藏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); 
        } 
       } 
      });