I have space between my tabs. I looked at all the possible solutions on StackOverflow and added them but still the space exists between them.
My tab code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="0dp"
>
<ImageView
android:id="#+id/tab_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
My Layout with tabs:
<?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"
android:orientation="vertical" >
<LinearLayout
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
android:id="#+id/tab5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="#+id/tab4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="#+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="0"
android:background="#drawable/bottom_image"
android:dividerPadding="0dp"
android:fitsSystemWindows="true"
android:gravity="fill"
android:showDividers="none"
android:tabStripEnabled="false"
android:visibility="visible" >
</TabWidget>
</LinearLayout>
</TabHost>
I added the following in code as well:
mTabHost.getTabWidget().setStripEnabled(false);
mTabHost.getTabWidget().setDividerDrawable(null);
if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.HONEYCOMB) {
mTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
}
But still it shows space between tabs. Am I missing something?
I have not got chances to check these from the android IDE. but I suppose this would work.
<?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"
android:orientation="vertical" >
<LinearLayout
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">
<FrameLayout
android:id="#+id/tab5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0" />
<FrameLayout
android:id="#+id/tab4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0" />
<FrameLayout
android:id="#+id/tab3"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0" />
<FrameLayout
android:id="#+id/tab2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0" />
<FrameLayout
android:id="#+id/tab1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0" />
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="0"
android:background="#drawable/bottom_image"
android:dividerPadding="0dp"
android:fitsSystemWindows="true"
android:gravity="fill"
android:showDividers="none"
android:tabStripEnabled="false"
android:visibility="visible" >
</TabWidget>
Here, I have gave a weightSum = 100.0 and divided this equivalently to all the childs.
Related
Below I listed the xml code.That shows the tab bar at the bottom of the screen.
layout_home.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#android:id/tabs" >
<FrameLayout
android:id="#+id/tab_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="#+id/tab_video"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="#+id/tab_audio"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<FrameLayout
android:id="#+id/tab_blog"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<FrameLayout
android:id="#+id/tab_gal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<FrameLayout
android:id="#+id/tab_more"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/top_bar"
android:divider="#null" />
<!-- android:background="#d8e49c" -->
</RelativeLayout>
</TabHost>
</LinearLayout>
Screenshot:
I need to move that tab bar to top of the screen.Thanks in advance.
Does this work for you....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#android:id/tabs" >
<FrameLayout
android:id="#+id/tab_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="#+id/tab_video"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="#+id/tab_audio"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<FrameLayout
android:id="#+id/tab_blog"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<FrameLayout
android:id="#+id/tab_gal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
<FrameLayout
android:id="#+id/tab_more"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher"
android:divider="#null" />
<!-- android:background="#d8e49c" -->
</RelativeLayout>
</TabHost>
</LinearLayout>
Stephen use this to move your tab on top of the screen in tour tabhost
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
</TabWidget>
<LinearLayout
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="0px"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
I have a problem with my android app. My application has two tabhost and It works well but the layout doesn't work well like the following picture:
The problem is that the FrameLayout overlaps with the lower tabhost and I dont solve it.
This is my activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TABHOST SUPERIOR -->
<RelativeLayout
android:id="#+id/l1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="right"
android:layout_alignParentTop="true">
<android.support.v4.app.FragmentTabHost
android:id="#+id/tabhost_sup"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_weight="0"/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#android:color/holo_blue_dark"/>
</ScrollView>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>
<!-- TABHOST INFERIOR -->
<RelativeLayout
android:id="#+id/l2"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_weight="1"
android:gravity="right"
android:layout_alignParentBottom="true"
android:background="#android:color/background_light" >
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/RelativeLayout1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="0dp"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</RelativeLayout>
</RelativeLayout>
I have tried the following code. which aligns the framed layout above the tab widget but it still didn't work
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" />
<FrameLayout
android:id="#+id/tabFrameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_above="#android:id/tabs"
/>
</RelativeLayout>
</android.support.v4.app.FragmentTabHost>
edit
i am using FragmentTabHost. maybe that could be why it's not changing position
The solution which finally worked for is the following:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
Try this
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<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:visibility="visible"
/>
</LinearLayout>
Maybe like this:
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" />
</RelativeLayout>
<FrameLayout
android:id="#+id/tabFrameLayout"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
I'm having a problem with the TabWidget Layout.
How can I combine the tab with the content as it always shows this fading edge:
The graphics are perfect. I set the android:tabStripEnabled="false" but still it keeps showing me the line that separates between the tabs and the frame layout.
this is the XML code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="#drawable/background"
tools:context=".MainActivity" >
<include layout="#layout/action_bar" />
<TabHost
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tabStripEnabled="false"
android:divider="#null"
android:showDividers="none" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/grger"
android:fadingEdge="none" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
First of all sorry! I really have tried to use StackOverFlow to find the answer to this. I've seen an answer here -Android: Tabs at the BOTTOM which other people are understanding, but I cannot get my head around the solution.
My cut down XML code is this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical"
android:padding="5dp" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-5px"
android:layout_weight="0"
android:background="#ffff0000" >
</TabWidget>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
How can i get the selection of tabs to be displayed at the bottom? Many thanks
for this you will have to use RelativeLayout instead of LinearLayout than you can use android:layout_alignParentBottom="true" property inside TabWidget
Change
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-5px"
android:layout_weight="0"
android:background="#ffff0000" >
</TabWidget>
</LinearLayout>
To
<RelativeLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="-5px"
android:layout_weight="0"
android:layout_alignParentBottom="true"
android:background="#ffff0000" >
</TabWidget>
</RelativeLayout>