I already wrote 2 activities and now I want them to be in a tabHost (2 tabs, each activity in a tab).
I saw some code but none of them was good for me.
The 2 activities are complicated so I can't marge them into one class.
What can I do ?
Thanks.
If you could do this, i mean load several Activities at the same time you will have memory issues, You should use Tabs with Fragments, so i suggest the use of FragmentTabHost, convert your activities into Fragments and load it in a FragmentTabHost, this is an example:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="#android:id/tab_content1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="#+id/tab_content2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
Related
I have a problem with the navigation: I created a tabbed application using MvxTabsFragmentActivity and all worked great until I start navigating inside the tabs; If I navigate one level inside one tab and then I change the tab, on the second tab I am presented with the content from the first tab. Have anyone encountered this problem?
I created the tabs using TabHost.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/actualtabcontent"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#+id/tabContainer"/>
<LinearLayout android:id="#+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TabHost android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="7dp"
android:background="#drawable/gradient_border_top"
android:orientation="horizontal" />
<TabWidget android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_weight="0"
android:background="#color/white" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</LinearLayout>
</RelativeLayout>
Each time I am navigating inside the tabs the content of actualtabcontent is replaced.
Expected navigation:
Tab A: A1 -> A2.
Tab B: B1 -> B2.
Switching between tabs should display the content for the selected tab
'You need to clear the cache while moving to the next tab.
if you are getting data from server using volley then use'
stringRequest.setShouldCache(false);
'before passing your stringrequest to requestqueu.'
'if you are using something else then find a way to clear cache before loading new data.'
'hope you get the answer if not please explain your question.'
I want to design 4 tabs bottom at the screen, but my problem is tabs are hidden at bottom of the screen.But in an empty activity the tabs are shown. see the images.
this image is showing tabs with and without activity
here is my code, xml and java
Try setting property
android:layout_above="#id/tabs" to FrameLayout
Edit:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#android:id/tabs"
android:layout_alignParentTop="true" />
</RelativeLayout>
</TabHost>
I am Unable to set Scroll view inside my android app development when i am adding scroll view it overlapping tab head and also unable to switch tabs thank you for your valuable time..`
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bRecharge">
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/tabhost">
<LinearLayout
android:id="#+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/Mobile"
android:layout_width="match_parent"
android:layout_height="419dp"
android:orientation="vertical">
</RelativeLayout>
<RelativeLayout
android:id="#+id/DTH"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</RelativeLayout>
<RelativeLayout
android:id="#+id/Datacard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</RelativeLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
</TabHost>`
Open <TabHost> . In your code you're adding </TabHost> but I don't see anywhere the open of it.
Sorry friends .. its very simple to add scroll view in tabhost add scroll view the different activity xml files that we used in the main tabhost
Thank you so much
I've been working on a small project that consists of a GUI with a number of tabs. I'm quite new with the concept of fragments however it seems that they're a best practice within the android tab landscape. I managed to code a simple tab app, that switches between 3 tabs.
The only issue I have is when I try placing the tabs at the bottom of the screen. When they're at the bottom, the tab widget covers the container(framelayout in this case) and so nothing happens, the screen remains the same when clicking the various tabs.
The following XML layout represents the good version( where the tabs are at the top of the screen):
<?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="#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"
>
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="#+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
</LinearLayout>
The following XML layout represents the version that isn't working, when the tabs are at the bottom of the screen:
<?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="#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"
>
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
/>
<FrameLayout
android:id="#+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
/>
</RelativeLayout>
</TabHost>
</LinearLayout>
I changed the layour to relativelayout and added this command: android:layout_alignParentBottom="true" to the tabwidget. Does anyone have an alternative idea of how I can sort this issue? Thanks in advance.
In general using tabs at the bottom of the screen is a bad solution (see Android design guidelines).
For your solution: put TabWidget at the end of list of view. Because of drawing is a line process and fragments this your case are drowed upper TabWidget
You can use weight instead. Try this layout marking
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
You can replace FragmentTabHost with own TabHost class. So, your tabs will be at the bottom of the screen.
Be careful with nested weights (they are bad for performance) and deeping in view hierarchy (especially for android < 4).
I'm developing an Android app implementing the a tabhost, viewpager, and a top-side sliding drawer and tabs at the bottom. The application uses the android-support-v4 FragmentPagerAdapter, which can be found in the samples of the v4-support-package. A reference can be found here:
http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
I can't seem to get both the Sliding Drawer and the TabHost to appear on the screen at the same time.
Here is my layout. The com.mobicartel... block is a custom sliding drawer. -------------------------------------------------------------------------------------------
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my="http://schemas.android.com/apk/res/com.mobicartel.tabsandpager"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.mobicartel.tabsandpager.slidingdrawer.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/com.mobicartel.tabsandpager"
android:id="#+id/drawer"
my:direction="topToBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
my:handle="#+id/handle"
my:content="#+id/content">
<include
android:id="#id/content"
layout="#layout/pen_content" />
<ImageButton
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="40px"
android:src="#drawable/sliding_drawer_handle_bottom" />
</com.mobicartel.tabsandpager.slidingdrawer.MultiDirectionSlidingDrawer>
<FrameLayout
android:id="#+id/tab_host_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/drawer">
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
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="0dp"
android:layout_weight="0"/>
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dip"/>
</LinearLayout>
</TabHost>
</FrameLayout>
The content of TabHost actually isn't being displayed. Instead, the tab listener & viewpager listener control each other so they are in sync. The ViewPager is populated with fragments by a special adapter.
Any ideas?
Does anybody
I've never used TabHost with tabs at the bottom, because it is advised against (in the official Design Guidelines), however, it appears that you are using the hack found here: https://stackoverflow.com/a/2710404/377260.
I notice that your FrameLayout weight is 0, along with the height and width. Try setting them to:
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1"/>
as found in the answer linked to.