Skip to content Skip to sidebar Skip to footer

Some Android Phones Cutting Off Ui At Bottom & Right Of Screen

I've tested on several other devices and my UI looks fine. However on the Samsung Note 3, the UI is getting cut off on the bottom. I have logged the system specs and done the math.

Solution 1:

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

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

EDIT: 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
    publicvoidonGlobalLayout() {
        parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        int parentHeight = parent.getHeight();
        // do your positioning
    }
}

Solution 2:

My buttons height was not having its view bounds adjusted and as such had the wrong height. Setting setAdjustViewBounds(true) fixed the issue.

The reason it only 'appeared' to happen on some phones and not others is the down and upsampling. If the density of the asset was such that it could fit inside the button, then it would look normal. But on the Samsung 3 (in this specific case) the drawable asset was coming in at a size of 136 x 136 and the button was not able to resize it to be smaller. When I set the adjustsBounds to true, it was allowed to shrink it to the right size.

Post a Comment for "Some Android Phones Cutting Off Ui At Bottom & Right Of Screen"