'Tab icon should only be displayed when it is selected

I'm working on tablayout and I have created a drawable i.e. show logo for selected tabitem only and hide for rest. Since, drawable isn't loosing the dimension and @android:color/transparent still taking space which makes tablayout messy in terms of UX.

below is my drawable code.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/selected_tab_icon" />
    <item android:drawable="@android:color/transparent" android:state_selected="false" />
</selector>

Is there is any way by which I can hide those unselected tabs vacant spaces of transparent drawable?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source