how to make tabs at the bottom.

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to make tabs at the bottom.

Postby ashish » Mon May 11, 2009 4:18 pm

Hi,

I have one doubt in Tabhost . I want the tabs to display at bottom instead of top programatically. i tried to use setGravity but its not working.. Please help me out from this.


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

TabHost tabHost = getTabHost();

TabWidget tabWidget = new TabWidget(this);
tabWidget.setId(android.R.id.tabs);
tabWidget.setGravity(Gravity.BOTTOM);
tabHost.addView(tabWidget, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
tabHost.setup();

LayoutInflater.from(this).inflate(R.layout.tabs1, tabHost.getTabContentView(), true);



tabHost.addTab(tabHost.newTabSpec("")
.setIndicator("", getResources().getDrawable(R.drawable.pic1))
.setContent(new Intent(this, List1.class)));

tabHost.addTab(tabHost.newTabSpec("")
.setIndicator("", getResources().getDrawable(R.drawable.pic2))
.setContent(new Intent(this, List2.class)));

tabHost.addTab(tabHost.newTabSpec("")
.setIndicator("", getResources().getDrawable(R.drawable.pic3))
.setContent(new Intent(this, List3.class)));

tabHost.addTab(tabHost.newTabSpec("")
.setIndicator("", getResources().getDrawable(R.drawable.pic4))
.setContent(new Intent(this, List4.class)));
}
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Top

setPadding()

Postby satishkumar_lskin » Tue May 12, 2009 6:18 am

Hi,
U can use setPadding(int left , int top , int right , int bottom ) for tabWidget to bring it at the bottom. This works.
Also make sure that the FrameLayout object associated with the TabHost that displays the tab content is also displayed properly in that case. I haven't tried this, but make sure that leaving the FrameLayout object in its original position ( without using setPadding() for FrameLayout) gives the behaviour, u desire.

Regards,
Satish
satishkumar_lskin
Developer
Developer
 
Posts: 32
Joined: Mon Oct 20, 2008 8:15 am
Location: Coimbatore , TamilNadu, India

Postby ashish » Tue May 12, 2009 7:49 am

hey thanks satish..it works..below is my code which might help others..









<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TabHost android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:paddingTop="370px"/>

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="65px"> <!-- you need that if you don't want the tab content to overflow -->
<LinearLayout
android:id="@+id/edit_item_date_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/edit_item_geocontext_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lieu"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/edit_item_text_tab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px">
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>












public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);



TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
// don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
tab_host.setup();

TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
ts1.setIndicator("tab1");
ts1.setContent(R.id.edit_item_date_tab);
tab_host.addTab(ts1);

TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
ts2.setIndicator("tab2");
ts2.setContent(R.id.edit_item_geocontext_tab);
tab_host.addTab(ts2);

TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
ts3.setIndicator("tab3");
ts3.setContent(R.id.edit_item_text_tab);
tab_host.addTab(ts3);

tab_host.setCurrentTab(0);




}
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Re: how to make tabs at the bottom.

Postby ZeroTruths » Sat Jun 26, 2010 3:32 am

Excellent! This helped me quite a bit.
However, I was irked that you were using a fixed amount of pixels, so I replaced
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:paddingTop="370px"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

with
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:layout_gravity="bottom"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

and now the tabs are on the bottom, regardless of screen size.
ZeroTruths
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Feb 10, 2010 7:06 pm

Re: how to make tabs at the bottom.

Postby ashish » Sat Jun 26, 2010 6:56 am

yup that's good..u should always dp or relative parameter.
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Re: how to make tabs at the bottom.

Postby rkjhaw » Thu Jul 22, 2010 10:54 am

Hi,
Thanks,
I've one problem, I'm trying to put pics in side the tab.
How to add image into tabs

--RKJ
rkjhaw
Freshman
Freshman
 
Posts: 5
Joined: Mon May 10, 2010 4:02 pm

Top

Re: how to make tabs at the bottom.

Postby orhanc1 » Fri Jul 23, 2010 10:06 pm

rkjhaw wrote:Hi,
Thanks,
I've one problem, I'm trying to put pics in side the tab.
How to add image into tabs

--RKJ

I get the feeling you're trying to make iPhone-like tabs. There's a link somewhere on the forum where someone has already done it. If you're just looking for the thrill of accomplishing it alone then by all means go ahead. Otherwise, a quick search can save you some time :)

EDIT:
Ok, so I stumbled across the post so here it is:
code-snippets-for-android-f33/iphone-tabs-for-android-t14678.html
Last edited by orhanc1 on Sat Jul 24, 2010 10:22 pm, edited 1 time in total.
orhanc1
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Jul 22, 2010 9:54 pm
Location: Canterbury, Kent, England

Re: how to make tabs at the bottom.

Postby ashish » Sat Jul 24, 2010 7:57 am

IF u want i-phone like look..u can use tablelayout at the bottom and use imageview as it's content.

I am saying tablelayout because in landscape mode it's cell get expand automatically and thus it looks good in both mode.
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Re: how to make tabs at the bottom.

Postby khot.darshan » Fri Aug 17, 2012 7:36 am

Superb Work Done..Well Appreciated
khot.darshan
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Aug 17, 2012 7:34 am

Re: how to make tabs at the bottom.

Postby lovelife » Sat Aug 18, 2012 9:13 am

Why my site April lace wigs, can't be display well on Android system ?
lovelife
Freshman
Freshman
 
Posts: 6
Joined: Sun Jul 29, 2012 2:55 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests