Marc A. Marc A. - 6 months ago 39
Android Question

TabLayout not expanding over whole screen width

Image of my Problem

I want to fill the space left and right of my TabLayout aswell, so that it fills the whole screen. However I just cant get it to work. This is my Layout.xml.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cytek2806northman.tabtestproject.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_height = "wrap_content"
android:layout_width = "match_parent"
>

<android.support.design.widget.TabLayout
android:layout_height = "wrap_content"
android:layout_width = "match_parent"
android:id="@+id/tabLayout"
app:tabMode="scrollable"
app:tabGravity="fill"
>
</android.support.design.widget.TabLayout>


</android.support.design.widget.AppBarLayout>

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


</RelativeLayout>


Wow, nvm... I just fixed it myself. Thanks anyways. :D

Solution was removing

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

Answer

Since I can't se what the values is of your margins in the relative layout, then it must be theese attributes that causes the empty spaces. Remove them and it should work, since anything else looks right.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="cytek2806northman.tabtestproject.MainActivity">