My application has android:targetSdkVersion set to 11. It uses TabHost and TabWidget with two tabs. However, the android:minSdkVersion is set to 7 (Android 2.1).
I use the Android Support Library (android-support-v13.jar). My tabs look fine everywhere I've been able to test, except in 2.1 where they appear to be clipping parts of the view that forms the tab's content. This problem in reproducible in the emulator as well.
Here's the relevant section of the layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/repeat_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android: />
<FrameLayout>
...
</FrameLayout>
</TabHost>
</LinearLayout>
Here's how I expect the tabs to look:
Here's what I get in 2.3 devices:
Basically, it seems the Tabs are taller than they need to be and also unnecessarily overlapping with the contents of the FrameLayout below.
SOLUTION:
Mostly for future visitors, if you're looking to have you tabs appear consistent on all platforms down to 2.1, the only solution is to use custom Tab views. You'll find an excellent tutorial here.
Try This
<?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:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" android:id="#android:id/tabs"
android:orientation="horizontal" />
<FrameLayout android:layout_width="fill_parent" android:layout_height="0dp"
android:layout_weight="1" android:id="#+android:id/realtabcontent" />
</LinearLayout>
</TabHost>
Hope it helps...!! Cheers...
Related
I agree before-hand with anyone who wants to make the argument that tabs should be at the top of the screen, but I can't control the requirements for my app :) . I have to build an app with tabs at the bottom of the screen. I'm using SDK 14 and Actionbars. Is this even possible? I have already built a layout with the tabs at the bottom, but when I add the tabs to the ActionBar, they are automatically rendered at the top of the screen.
Any ideas would be really appreciated, and thank you all for taking the time to read this post.
You can use Tabhost for requirement,and inside tab.xml you can write below code . This will work fine .
<?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">
<RelativeLayout 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="fill_parent"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:tabStripEnabled="false"
android:layout_alignBottom="#android:id/tabcontent"
android:background="#000000" />
</RelativeLayout>
</TabHost>
I was using tabhost and trying to disable the tab border line. I used this android:tabStripEnabled="false"
in my XML but it doesn't seem to be working, the line was still there, and I try other way like making changes in the style.xml(which I found from stackoverflow) but it doesn't work either. Any idea?
my tab 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
xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#android:id/tabs" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FFFFFF"
android:tabStripEnabled="false"
android:layout_gravity="bottom" />
</RelativeLayout>
</TabHost>
</LinearLayout>
You can remove the bottom strip of tabs and divider between tabs by using following statement.
TabHost t;
t.getTabWidget().setStripEnabled(false);
t.getTabWidget().setDividerDrawable(R.drawable.ic_launcher);
It requires minSDK 8 (2.2) at least... Review your manifest.
Be sure that there insn't a line, in your code, setting tab's background (I had this problem ...) ;)
I'm sory for my poor Englisch. I come from Holland, and I'm just 14.
I am practicing my android development skills, but I have a problem. If I create a tab menu comes a horizontal line below. With a black background you don't see it, but if it is white you'l see it.
![http://img703.imageshack.us/img703/503/emulator.png][1]
My question is rather simple. How can I delete that line? The XML layoutfile of this tab menu is displayed below.
<?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:background="#ffffff">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
please try by removing android:padding="5dp" from the FrameLayout.
have you tried xml attributes in here?
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Anyone know what this error mean for android tabs?
I have been trying to do the TabHost tutorial in the SDK but for some reason, is appears to break. On Step 4 I copy and paste the xml code, I get an error that prevents it from inflating properly. the error is:
Error in an XML file: aborting build.
This is in the graphical layout of the xml file.
Error during post inflation process:
TabHost requires a TabWidget with id "android:id/tabs",
View found with id "tabs" is 'com.android.layoutlib.bridge.MockView'
The xml file Itself has this in it.
<?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:orientation="vertical"
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" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Am I doing something wrong?
Use this template:
<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/tab" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="#+id/tab1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"/>
<LinearLayout android:id="#+id/tab2" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"/>
</FrameLayout>
</LinearLayout>
</TabHost>
See step 5 , your Activity must extend TabActivity, not Activity
Now open HelloTabWidget.java and make it extend TabActivity:
Switch to android target 3.0 or 3.1 in the graphical layout itself. You can find the drop down list on the top right corner
You can use the updated rendering library found here: Android Tools.
Just extract the directories found in \layoutlib\[platform version] to \[sdk dir]\platforms\[platform version] and let it override the layoutlib.
look at this:
http://www.eurodroid.com/pics/android_foursquare_update_1.jpg
Someone knows how is structured this layout?
Is a 3 tab layout, but the content of this tab?
Is a table, a ListAdapter, what is?
Thank you a lot.
The Foursquare app for Android is open source. I believe what you are looking for is their main_activity.xml:
<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" >
<!-- Background color should be the last value in the selected tab gradient. -->
<LinearLayout
android:id="#+id/tabBackground"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dip"
android:background="#4d4d4d">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<!-- A paddingTop of zero will remove the strip below the tabs. -->
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dip" />
</LinearLayout>
</TabHost>
The content of that tab specifically is just a customized ListView. As pointed out by Bryan, you can browse the source code to see the exact XML layouts they used.