Background
I have a TabLayout
with some elements in it.
In portrait mode, the elements don't have enough space to appear. So I used:
app:tabMode="scrollable"
On the other hand, in landscape mode, the elements have excess space and I want it to be centered. So I used this approach:
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/Tab"
android:layout_width="wrap_content" <!-- Used wrap_content -->
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" <!-- And CenterHorizontal -->
app:tabMode="scrollable" />
But since the background color is null in my MainActivity
:
window.setBackgroundDrawable(null)
The TabLayout
appears with (Black Wings) in Landscape Mode.
I want it to have @color/colorPrimary
wings instead.
So I had two options:
1- Make the background of my MainActivity
, not null (aka @color/colorPrimary
)
I don't want to do that since all my fragments in the companion ViewPager
will experience Overdraw
because they all have different backgrounds set programmatically.
OR
2- Add a Container to incubate my TabLayout
and set its background with my @color/colorPrimary
, like so:
<RelativeLayout
android:id="@+id/tabs_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/Tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:tabMode="scrollable" />
</RelativeLayout>
I will discuss the problems of this approach below.
Problem
Using Option #2 above:
There is still a tiny bit of Overdraw
where the two views, parent RelativeLayout
and child TabLayout
, overlap.
So how can I remove this extra bit of Overdraw
?
Thoughts
I am thinking of overriding the OnDraw
method in the View
class to suit my needs, but the challenge is that how to know the actual positions I would need to ClipRect()
Another thought is to come up with a, you know, (simpler) approach different from Option #2 above, to solve the Background
issue.
Thanks in advance.