如何在android中设置屏幕底部的标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2401140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:43:18  来源:igfitidea点击:

how to set the tabs in the bottom of the screen in android?

androidandroid-layoutandroid-emulatorandroid-tabs

提问by Praveen

i am working on tabactivity.

我正在研究 tabactivity。

i wanna show my tabwidget below the tabcontent(framelayout).

我想在 tabcontent(framelayout) 下方显示我的 tabwidget。

i done it by setting the tabwiget tab attribute as

我通过将 tabwiget 选项卡属性设置为

android:gravity="bottom"

but the framelayout cant align with those tabs.

但框架布局无法与这些选项卡对齐。

that is the tabs are shown at the bottom of the screen and overlap the framelayout

即选项卡显示在屏幕底部并与框架布局重叠

how to do that? if set some height value to the framelayout it not optimized for all screens of android. what can i do? any idea???

怎么做?如果为 framelayout 设置了一些高度值,则它不会针对 android 的所有屏幕进行优化。我能做什么?任何的想法???

采纳答案by reflog

or just use a custom one from: http://code.google.com/p/androidtabs/

或者只是使用来自:http: //code.google.com/p/androidtabs/的自定义

it allows tabs on the bottom

它允许底部的标签

回答by Swapnil Sonar

The basic concept behind the Tab-Activityas follows

背后的基本概念Tab-Activity如下

TabHostis a container for a tabbed window view. This object holds two children: a set of tab labels that the user clicks to select specific tab, and a FrameLayout object that displays the content of that page.

TabHost是选项卡式窗口视图的容器。该对象包含两个子项:用户单击以选择特定选项卡的一组选项卡标签,以及显示该页面内容的 FrameLayout 对象。

The individual element are typically controlled using this container object, rather then setting values on the child elements themselves.

通常使用此容器对象控制单个元素,而不是在子元素本身上设置值。

TabWidgetdisplays a list of tab labels representing each page in the parent's tab collection. The container object for this widget is TabHost. When a user selects a tab, this object sends a message to container, TabHost, to tell to switch the display page. The container TabHost is used to add labels, add the callback handler, and manage callbacks.

TabWidget显示代表父标签集合中每个页面的标签标签列表。此小部件的容器对象是 TabHost。当用户选择一个选项卡时,该对象会向容器 TabHost 发送消息,告知切换显示页面。容器 TabHost 用于添加标签、添加回调处理程序和管理回调。

so adjust your layout as follows -

所以调整你的布局如下 -

<?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:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

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

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="-3dip"
        android:layout_weight="0" >
    </TabWidget>
  </LinearLayout>

  </TabHost>

回答by Ralphleon

Android's examples to the rescue!

Android 的例子来拯救你!

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

Just swap tabcontent and tabs in res/layout/main.xml:

只需在 res/layout/main.xml 中交换 tabcontent 和 tabs:

   <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="fill_parent"
            android:padding="5dp" />        
   <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

   </LinearLayout>

回答by MduSenthil

Please Check the following link

请检查以下链接

There are two ways to display tabs at the bottom of a tab activity.

有两种方法可以在选项卡活动的底部显示选项卡。

1) Using relative layout 2) Using Layout_weight attribute

1) 使用相对布局 2) 使用 Layout_weight 属性

http://justkumar.blogspot.com/2011/09/tabs-at-bottom-of-tabactivity-by.html

http://justkumar.blogspot.com/2011/09/tabs-at-bottom-of-tabactivity-by.html

回答by Jiju Induchoodan

Check this

检查这个

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:id="@android:id/tabhost">
<LinearLayout android:id="@+id/LinearLayout01"
android:orientation="vertical" 
android:layout_height="fill_parent"
android:layout_width="fill_parent">

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">

    <TabWidget 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:layout_gravity="bottom" 
android:id="@android:id/tabs">
</TabWidget>
</FrameLayout>

</LinearLayout>

回答by Anil M H

this is the code for bottom tab

这是底部选项卡的代码

<TabWidget
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_gravity="bottom" 
android:background="#0000"
android:id="@android:id/tabs"
/>



  "android:layout_gravity="bottom"