Adview显示在软键盘顶部

发布于 2024-11-02 01:57:10 字数 1761 浏览 1 评论 0原文

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

我在清单中为所有活动定义了 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>

I have just integrated AdWhirl into my app. I have the AdWhirl view set to show up on the bottom of the layout of my main activity. I have a few EditText boxes on my main layout and when the app first launches clicking the text boxes displays the soft keyboard normally. However when I go to another activity and back to my main activity, then click the EditText the soft keyboard pops up with the AdWhirl view on top, covering my EditText box. I have been struggling with this for days. Any help would be appreciated.

I have android:windowSoftInputMode="adjustPan" defined in my manifest for all activities.

Here is my main.xml layout:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦回梦里 2024-11-09 01:57:10

尝试为您的 EditText 框设置 onFocusChangeListener 。当它们获得焦点时,将 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);

            }
        });

Try setting a onFocusChangeListener to your EditText boxes. When they get focus, set the AdWhirl view visibility to View.INVISIBLE so it doesn't obstruct the textboxes and then set it back to visible once focus is lost.

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);

            }
        });
謸气贵蔟 2024-11-09 01:57:10

我尝试设置 android:windowSoftInputMode="adjustPan"。
它隐藏了 adMob 横幅也隐藏了 EdiText。
我也尝试了接受的答案,但编辑文本可以在不打开键盘的情况下获得焦点。
所以我找到的解决方案是在键盘打开时隐藏 adMob 横幅。
我学会了如何检测键盘是否打开 此处
这是我的解决方案:

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);
                    }
                 }
            });

I tried setting android:windowSoftInputMode="adjustPan".
it hides the adMob banner but also the EdiText.
I also tried the accepted answer, but the edittext can get focus without the keyboard opens.
So the solution I found is to hide the adMob banner when the keyboard opens.
I learned how to detect if the keyboard opens here.
and here is my solution:

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);
                    }
                 }
            });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文