1

I am facing a problem. I have a custom layout for toolbar and in my activity xml, I am including this toolbar. The structure of my activity is:

  1. Toolbar layout on top using include tag.
  2. The ViewPager
  3. TabLayout at bottom to get bottom tabs.

The problem I am facing is that on some devices, it is coming out perfect but in a few devices (tested on moto G series devices) the bottom tab is leaving space.

Please Refer the Images below:

In Normal Phones when it shows expected UI

enter image description here

In MOTO G series

enter image description here

The xml code is following

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#efeded"
android:weightSum="11"
android:orientation="vertical">

<include layout="@layout/custom_tool_bar" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"

    android:layout_height="0dp"

    android:layout_weight="10" />

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    style="@style/BottomTabLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="#fff"
    android:layout_weight="1"
    app:tabIndicatorColor="@color/colorPrimaryDark"
    app:tabSelectedTextColor="@color/colorPrimaryDark"
    />

</LinearLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
The Bat
  • 1,085
  • 1
  • 13
  • 31
  • Possible duplicate of [How to set android TabLayout in the bottom of the screen?](https://stackoverflow.com/questions/33380668/how-to-set-android-tablayout-in-the-bottom-of-the-screen) – denvercoder9 Dec 06 '17 at 09:55

3 Answers3

2

For bottom tabs you can use bottomnavigationview it provides better performance and works in MOTO devices with out any problem. Check this

https://developer.android.com/reference/android/support/design/widget/BottomNavigationView.html

Nimisha V
  • 461
  • 4
  • 12
2
  1. remove android:weightSum=11 attribute in your parent LinearLayout;
  2. change ViewPager's android:layout_weight=10 attribute to android:layout_weight=1;
  3. remove TabLayout's android:layout_weight=1 attribute

and try again.

Anthonyeef
  • 2,595
  • 1
  • 27
  • 25
  • Looks like perfect answer. – IntelliJ Amiya Dec 06 '17 at 09:50
  • I did, but it didn't help. still it is leaving some space at bottom – The Bat Dec 07 '17 at 08:14
  • @TheBat That sounds strange. Do you have other device to test with? Does this only happen to Moto G? Also I notice that the second screenshot doesn't have soft navigation button, is there any relationship to your problem? – Anthonyeef Dec 07 '17 at 15:14
  • @IntelliJAmiya I have written an answer response,, please have a look. – The Bat Dec 08 '17 at 08:49
  • @Anthonyeef I have written an answer response,, please have a look. – The Bat Dec 08 '17 at 08:49
  • 1
    @TheBat as far as I can see, the reason that extra padding showing up is the override method you code to detect the system's navigationBar soft key existing or not. It has nothing to do with the xml layout you post before(and I think that xml layout would actually work without that detecting soft navigation key method). Maybe you should try to ask a new question about it, though I have seen some similar question before, and it actually seems to be different from devices to devices, different rom also. – Anthonyeef Dec 10 '17 at 03:56
0

I found the problem why is it happening. I have used a library - ResideMenu in my Activity and it has a function to detect whether the device has hardware Back and Menu buttons or the digital ones.

@Override
protected boolean fitSystemWindows(Rect insets) {

    int bottomPadding = viewActivity.getPaddingBottom() + insets.bottom;
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

    if (!hasBackKey || !hasHomeKey) {//there's a navigation bar
        bottomPadding += getNavigationBarHeight();
    }

    this.setPadding(viewActivity.getPaddingLeft() + insets.left,
            viewActivity.getPaddingTop() + insets.top,
            viewActivity.getPaddingRight() + insets.right,
            bottomPadding);
    insets.left = insets.top = insets.right = insets.bottom = 0;
    return true;
}

This is not working properly. For some devices it works fine but for some devices it's not able to determine the buttons. So in some devices it is going up leaving a space for digital buttons. Anyways, I could not find a solution for this, tried a few StackOverflow but it didn't work out, please post if anyone finds something.

The Bat
  • 1,085
  • 1
  • 13
  • 31