Hasan A Yousef
Hasan A Yousef

Reputation: 24948

How to show part of the Fragment under the TabLayout

I managed to crate "dots" Tab layout using the below codes:

layout.xml:

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


    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@drawable/tab_selector"
        app:tabGravity="center"
        app:tabIndicatorHeight="0dp"/>

</LinearLayout>

tab_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/tab_indicator_selected"
        android:state_selected="true"/>

    <item android:drawable="@drawable/tab_indicator_default"/>
</selector>

tab_indicator_default.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="2dp"
            android:useLevel="false">
            <solid android:color="@android:color/darker_gray"/>
        </shape>
    </item>
</layer-list>

tab_indicator_selected:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:innerRadius="0dp"
            android:shape="ring"
            android:thickness="4dp"
            android:useLevel="false">
            <solid android:color="@color/colorAccent"/>
        </shape>
    </item>
</layer-list>

For buttons styling, I used:

<style name="PrimaryFlatButton" parent="Theme.AppCompat.Light">
    <item name="android:buttonStyle">@style/Widget.AppCompat.Button.Borderless.Colored</item>
    <item name="colorControlHighlight">@color/colorAccent</item>
    <item name="colorAccent">@color/colorPrimary</item>
</style>

and called it as:

android:theme="@style/PrimaryFlatButton"

but noticed the lower part of the tabs is always above the TabLayout.

I need to be able to show textView or Button as below, what shall I do or change in the above (or ant where else) to get it this way?

enter image description here

UPDATE

What I'm getting so far is:

enter image description here

Upvotes: 2

Views: 832

Answers (1)

Muhammad Saad Rafique
Muhammad Saad Rafique

Reputation: 3189

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:gravity="bottom">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content" 
            android:layout_weight="1"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_alignParentBottom="true"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:tabBackground="@drawable/tab_selector"
            app:tabGravity="center"
            app:tabIndicatorHeight="0dp"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

    </LinearLayout>


</LinearLayout>

Make it like this it will do the job you wanted :) Hope it helps Best of Luck ! Happy Coding :) Here is outcome

Upvotes: 1

Related Questions