一些 Android 手机在底部和底部切断了 UI屏幕右侧 [英] Some Android Phones Cutting Off UI At Bottom & Right of Screen

查看:63
本文介绍了一些 Android 手机在底部和底部切断了 UI屏幕右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在其他几款设备上进行了测试,我的 UI 看起来不错.

I've tested on several other devices and my UI looks fine.

但是在三星 Note 3 上,UI 在底部被切断了.

However on the Samsung Note 3, the UI is getting cut off on the bottom.

我已经记录了系统规格并进行了计算.我的设备屏幕高度为 1920.

I have logged the system specs and done the math. I have the screen height of the device at 1920.

我有一个大小为 108 x 108 的按钮.

I have a button that is sized at 108 x 108.

我希望该按钮位于屏幕底部(我没有使用 XML,我使用的是 Java).

I want that button resting on the bottom of the screen (I am not using XML, I am using Java).

    _button.setMinimumHeight(buttonDimension);
    _button.setMaxHeight(buttonDimension);
    _button.setY(1920 - 108);

然而,这会导致按钮底部被切断(仅在三星 Note 3 上).此外,如果我尝试右对齐,那里也会有轻微的切断.它看起来像是在底部关闭了大约 25 个像素.

However this results (on only the Samsung Note 3) in the bottom of the button being cut off. Also if I try to right align there is a slight cut off there too. It looks like its off by about 25 pixels on the bottom.

这里发生了什么?

看起来三星将实际渲染窗口下方和右侧的较小区域视为屏幕高度"的一部分.

It looks like Samsung considers a smaller area below and to the right of the actual rendering window as part of the 'screen height'.

如果屏幕的实际显示高度与报告值不符,您知道如何获得屏幕的实际显示高度吗?

Do you know how I can get the actual display height of the screen in cases where its off from the reported value?

如果我使用 layoutparams 并对齐到底部,它确实可以完美运行,但我需要它来处理像素数据.

If I use layoutparams and align to bottom, it does work perfectly but I need it to work with the pixel data.

推荐答案

为什么要硬编码维度?仅仅因为屏幕高度是 1920x1080 并不意味着您实际上有很多像素可用于您的应用程序(除非您使用的是沉浸式全屏模式).

Why are you hardcoding dimensions in there? Just because the screen height is 1920x1080 doesn't mean you actually have that many pixels available for your application (unless you're using immersive full-screen mode).

您的按钮采用什么类型的布局?如果它在FrameLayout 中,只需将按钮的layout_gravity 设置为bottom|center_horizo​​ntal.从 Java 来看,这看起来像:

What type of layout is your button in? If it's in a FrameLayout, just set the layout_gravity of the button to bottom|center_horizontal. From Java, that would look like:

FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) _button.getLayoutParams();
params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
_button.requestLayout();

RelativeLayout?只需使用 layout_centerHorizo​​ntallayout_alignParentBottom :

RelativeLayout? Just use layout_centerHorizontal and layout_alignParentBottom:

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) _button.getLayoutParams();
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
_button.requestLayout();

查看您最近的编辑,您应该只使用父级的实际尺寸来确定定位.您可以将 OnGlobalLayoutListener 添加到父布局以确定其大小:

Looking at your recent edit, you should just use the actual dimensions of the parent to determine the positioning. You can add an OnGlobalLayoutListener to the parent layout to determine its size:

parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        int parentHeight = parent.getHeight();
        // do your positioning
    }
}

这篇关于一些 Android 手机在底部和底部切断了 UI屏幕右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆