I have five tabs in my list, you can see the three first tabs when TabActivity get started, then if I scroll to the right, the other two will also show up. Problem I have is that the next two tabs need to be tapped twice in order to start, and vice and versa for the first two tabs if the three last tabs are shown in screen.
Please, if anyone know how to solve this annoying stuff, I would be grateful.
Thanks in advance!
EDIT:
I found out that the real problem is when I scroll to end (left or right) which causes any tab to be tapped twice in order to work, someone who recognize this? I found that it can be tapped once when scrolled to the end (right or left), but only after 3 seconds. If I tap right away, it need to be tapped again to work.
My code (xml):
<?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">
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"/>
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Did you wanted to try the ViewFlipper (as in the new Android market).
Here is the entire code,
Set default page for ViewPager in Android
It sounds like you might be losing focus on the tabs.
Have you tried to implement:
android.view.ViewTreeObserver.OnScrollChangedListener
And set the focus back on the TabHost when this is triggered?
You may also try playing with setOverScrollMode() in your TabHost
Related
Good time!
My question is concerned to the arrange of tabs in Android apps. My app consisted 6 pages of tabs and, sure, in the running application these tabs decrease to the narrow rectangles - that's really looks bad. So, is there any cases to switch on some features in tabs to add controls with arrows (like in Windows), which are used to manage the visibility of concrete tab. For example, I have six tabs, after start user sees only three and some control to move hidden tabs on screen?
Yehh...... I think you don't need to use narrow rectangles to complete your task. You have better solution to put your TabView in ScrollView.
For example :
<?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">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
Refrence : Scrolling Tabs in Android
In order to ease your life, you can use a FrameLayout and on top of the TabWidget you can add a HorizontalScrollView with any number of buttons you want.
Then using the onClick method, when you click a specific button of this HorizontalScrollView, you can set the current tab of your activity.
This way you can also have easy theming to your "tabs"... Hope this helps.
My question is simple. Is it possible to create tabs entirely in xml? My app has only one activity. I want to have 2 tabs that show the same data but in slightly different layouts. It seems like it should be but I cannot find anything on it.
TIA,
Mark
You can do something like this. Your layout for each tab would go inside a tabwidget. This will have it's limitations that you would easily get around if you employ a simple TabHost
<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">
<!-- Tabs at bottom of screen -->
<TabWidget
android:background="#drawable/textview_top"
android:layout_weight="12"
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="0dip"
/>
</TabHost>
Im developing an android-app which is basicly three tabs each tab with its own activity class. Here is the main.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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp">
<include layout="#layout/sorted_teams" />
<include layout="#layout/unsorted_teams" />
<include layout="#layout/about" />
</FrameLayout>
</LinearLayout>
</TabHost>
I have three includes each with its own activity class and layout xml file. What I want is a scroll on the content of each tab. How would you go about this? I tried enclosing the entire content of the layout files for the different tabs with a scrollview. I use tablelayout for the content of every tab. I tried eclosing the entire content with a scrollview but it wont show up. How would you recommend using scrollview if I want the content scrollable for each tab?
Use a ScrollView as the enclosing parent of TableLayout in each layout file of each of your tab activities.
Make sure your scroll-view definition is similar to
<ScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent">
Thank you for the quick answer! The solution you posted was my solution too but I had missed one detail that seemed to screw everyting up.
I tried again with enclosing everyting with a scrollview in each layout but I had fill_parent on layout_height, changing it to wrap_content seemed to fix everything, problem solved!
I dont know why we set it to fill_parent, I think it was because some issue with the background color.
I'm using the TabHost and TabWidget to create some tabs for an Android application. I see that the tabs show up vertically one next to the other. Is there any way to make tabs that are aligned horizontally (one on top of the other) ?.
I'm creating the tabs like this:
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
</FrameLayout>
</LinearLayout>
Something like this is what I need to do:
Try this one: https://code.google.com/p/themissingtabwidget/ . This is an open-source implementation based on the original tab widget that also works in horizontal mode.
I'm not certain, but I don't think there's much you can do with the default behavior. Android's tab support in general seems a bit clunky to me. But let me know if you do get this working -- I might be able to use it myself!
FWIW, I did my own tab behavior using image buttons and other control elements. In my case, I was trying to come up with tabs that didn't use so much screen real estate.
I am using six tabs in tab view. In portrait mode tab size become very small .So i want to scroll the tabs in horizontal so that size of each tab will remain original . How we can do this?
Is this what you are looking for? http://blog.uncommons.org/2011/04/18/scrolling-tabs-in-android/
There are a lot of solutions on the web for this but they're all complicated and unnecessary. If you are trying to make the tabs on the top of the screen scroll-able then you can use this simple implementation I have shown below. Hope this helps.
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>