相对布局内的文本视图和按钮在 android oreo 和 pie 中不可见,但在其他 android 版本中完全可见

Textview and button inside the relativelayout not get visible in android oreo and pie but visible in other android version perfectly

relativelayout 中的文本视图和按钮在 android oreo 和 pie 中不可见,但在其他 android 版本中完全可见。

if (mPromocodeCheckBox != null) {
            mPromocodeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (inputMethodManager == null)
                        inputMethodManager = (InputMethodManager) ALTCommonUtils.currentActivity.getSystemService(Context.INPUT_METHOD_SERVICE);

                    if (mPromocodeLayout != null) {
                        if (isChecked) {
                            mPromocodeLayout.setVisibility(View.VISIBLE);
                            if (inputMethodManager != null && mPromocodeEditText != null) {
                                mPromocodeEditText.requestFocus();
                                inputMethodManager.showSoftInput(mPromocodeEditText, InputMethodManager.SHOW_IMPLICIT);
                            }
                            if (mPromocodeApplyButton != null)
                                mPromocodeApplyButton.setVisibility(View.VISIBLE);

                            if (mPromocodeEditText != null)
                                mPromocodeEditText.setEnabled(true);
                        } else {
                            mPromocodeLayout.setVisibility(View.GONE);
                            HandleViewsUtils.TextView_SetText(mPromocodeMsg, "");

                            if (inputMethodManager != null && mPromocodeEditText != null) {
                                HandleViewsUtils.EditText_SetText(mPromocodeEditText, "");
                                inputMethodManager.hideSoftInputFromWindow(mPromocodeEditText.getApplicationWindowToken(), 0);
                            }
                        }
                    }
                }
            });
        }

为了您的参考,我附上了 xml 代码的屏幕截图:

第一个屏幕截图显示了奥利奥下方和奥利奥上方的正常屏幕

当我点击奥利奥下方的促销代码复选框时,第二张截图完美显示:

当我点击 oreo 和 pie 中的促销代码复选框时,第 3 个屏幕截图显示不完美

您的 xml 屏幕截图读起来很痛苦,但我刚刚意识到您使用的是 fill_parent 而不是 match_parentFILL_PARENT 在 API 8 之后被弃用; Google Developer Documentation Source. Why you should use Match Parent.

也许是时候转向最近引入的方法、设计模式和库了。开始使用约束布局而不是相对布局。 Benefits of Constraint Layout and its introduction in Android Studio 2.2 onwards. Stop using Relative Layouts and use them only when very necessary. Google I/O Talk of 2018 on Layouts, Link。您不知道 Google 什么时候会决定弃用它,然后您的项目就会停止工作。

另一件要记住的事情是新的支持库 AndroidX,您应该开始将旧项目迁移到它。 AndroidX 将成为未来新的 singular 支持库,所有基于怪异数字的支持库都将停止使用。

最后最重要的事情是 你应该开始为 Android API 28+ 开发,这将由 Google 强制执行年以后; Google 开发人员 Youtube Video。因此,开始迁移到当前 APIs 和支持库。

希望对您有所帮助。

附录 确保 Android Studio 在您的代码库中发出有关弃用的警报。更多链接在这里;