Android Bottom Tab

Asked 2 years ago, Updated 2 years ago, 86 views

I've looked up a few posts, but I can't get an answer, so I'm asking you a question here Is there a way to put TabWidget at the bottom of the screen? What if there is?

I tried two things, but neither of them worked.

1) Set tabwidget under frameayout. 2) Set tabwidget's gravity to bottom

android tabwidget

2022-09-22 21:32

1 Answers

There is the simplest and most scalable solution to place at the bottom of the screen.

Place Linear Layout as Vertical and Frame Layout on TabWidget.

Set the layout_height of Frameayout and tabwidget to wrap_content. Set the android:layout_weight of the frameayout to 1.

TabWidget's android:layout_weight is set to "0". (0 is the default value, but I put it in to emphasize it) Set TabWidget's android:layout_marginBottom to "-4dp" (to remove the divider below)

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_weight="1"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:layout_marginBottom="-4dp"/>

    </LinearLayout>
</TabHost>


2022-09-22 21:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.