Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tablayout custom view not taking full height android?

I have a tablayout with 2 tabs. I am using custom view to set the tabs

Tablayout XML

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:tabPaddingBottom="-1dp"
        app:tabPaddingEnd="-1dp"
        app:tabPaddingStart="-1dp"
        app:tabPaddingTop="-1dp"
        app:tabGravity="fill"
        app:tabIndicatorHeight="5dp"
        app:tabMode="fixed" />

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

</LinearLayout>

Custom View XML

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:andorid="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@android:color/white"
andorid:text="XXX" />

Java code for tab set up

private void setupTabIcons() {
    TextView tabOne = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.tab_text, null);
    tabOne.setBackgroundColor(ContextCompat.getColor(getActivity(),R.color.tabText1));
    tabOne.setText(tabTitle[0]);
    tabLayout.getTabAt(0).setCustomView(tabOne);

    TextView tabTwo = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.tab_text, null);
    tabTwo.setBackgroundColor(ContextCompat.getColor(getActivity(),R.color.tabText2));
    tabTwo.setText(tabTitle[1]);
    tabLayout.getTabAt(1).setCustomView(tabTwo);
}

This is my output Tabs not taking full height

How do I match the height of the textview to tablayout height?

like image 580
WISHY Avatar asked Nov 14 '25 14:11

WISHY


1 Answers

Had to do it programmatically

ViewGroup.LayoutParams layoutParams = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

Setting the params to textview

tabOne.setLayoutParams(layoutParams);
like image 122
WISHY Avatar answered Nov 17 '25 10:11

WISHY



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!