Reputation: 1069
I'm developing a UI for my application and it's working fine on all devices of the size ratio 18:9 except in Xiaomi 18:9 devices.It creates unwanted space between Tab layout and status bar like this :
I don't add any top margin or padding for Tab layout.
My xml code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
android:id="@+id/tabCardView">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="@dimen/tabHeight"
android:id="@+id/tabLayout"
app:tabMode="fixed"
android:background="?attr/tabBackgroundColor"/>
</android.support.v7.widget.CardView>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
android:background="?attr/homeBackgroundColor"
android:layout_below="@+id/tabCardView"/>
</RelativeLayout>
I have no any idea why this happening.
Upvotes: 1
Views: 57
Reputation: 3253
What happens if you put this meta-data in the tag of your manifest? It could well be, that this device is using 18.5:9 and not plain 18:9
<application .... >
<meta-data
android:name="android.max_aspect"
android:value="2.1"/>
</application>
More information here: https://android-developers.googleblog.com/2017/03/update-your-app-to-take-advantage-of.html
Upvotes: 1
Reputation: 383
use CoordinatorLayout as parent layout and make android:fitsSystemWindows="false"
for example :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
android:id="@+id/tabCardView">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="@dimen/tabHeight"
android:id="@+id/tabLayout"
app:tabMode="fixed"
android:background="?attr/tabBackgroundColor"/>
</android.support.v7.widget.CardView>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
android:background="?attr/homeBackgroundColor"
android:layout_below="@+id/tabCardView"/>
</CoordinatorLayout>
</RelativeLayout>
it will works
Upvotes: 0