开发者

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

i am working on tabactivity.

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

i done it by setting the tabwiget tab attribute as

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 tha开发者_高级运维t? if set some height value to the framelayout it not optimized for all screens of android. what can i do? any idea???


The basic concept behind the Tab-Activity as follows

TabHost is 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.

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

TabWidget displays 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.

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>


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

it allows tabs on the bottom


Android's examples to the rescue!

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

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

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


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

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


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>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜