【问题标题】:how to set the tabs in the bottom of the screen in android?如何在android中设置屏幕底部的选项卡?
【发布时间】:2010-03-08 12:12:56
【问题描述】:

我正在处理 tabactivity。

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

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

android:gravity="bottom"

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

即标签显示在屏幕底部并与框架布局重叠

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

【问题讨论】:

标签: android android-layout android-emulator android-tabs


【解决方案1】:

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

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

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

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

所以调整你的布局如下 -

<?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>

【讨论】:

    【解决方案2】:

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

    它允许底部的标签

    【讨论】:

      【解决方案3】:

      Android 的例子来拯救你!

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

      只需在 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>
      

      【讨论】:

      • 两个认为我必须告诉你。 1. 除非你为你的 tabwidget 设置重力,否则它不起作用。 2. 当框架布局内容的高度大于屏幕高度时,tabwidget 会从您的屏幕失去其可见性。请试试你的例子,让我知道。
      【解决方案4】:

      请查看以下链接

      有两种方法可以在标签活动的底部显示标签。

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

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

      【讨论】:

        【解决方案5】:

        检查一下

        <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>
        

        【讨论】:

          【解决方案6】:

          这是底部标签的代码

          <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" 
          

          【讨论】:

            猜你喜欢
            • 2016-01-27
            • 1970-01-01
            • 1970-01-01
            • 2016-04-27
            • 1970-01-01
            • 1970-01-01
            • 2017-10-22
            • 2016-09-17
            • 1970-01-01
            相关资源
            最近更新 更多