i want to set scroll bar in tab host.in tab there is five tab but i want to display only three
tab at a time and how to make scrollbar for that so tab can be scroll for more tab...please provide me some solution.......
this is m xml file.....
<RelativeLayout
android:id="#+id/rl3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/gray" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/layTab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:gravity="center" >
<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="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
</HorizontalScrollView>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<fragment
android:id="#+id/fragment1"
android:name="info.tech.slidermenu.Home_feed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment2"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment3"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment4"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment5"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
this is class file....
public void tabselect() {
TabHost tab = (TabHost) findViewById(R.id.tabhost);
tab.setup();
tab.setHorizontalScrollBarEnabled(true);
TabHost.TabSpec spec = tab.newTabSpec("tab1");
spec.setContent(R.id.fragment1);
spec.setIndicator("Feed");
tab.addTab(spec);
spec = tab.newTabSpec("tab2");
spec.setContent(R.id.fragment2);
spec.setIndicator("tennis");
tab.addTab(spec);
spec = tab.newTabSpec("tab3");
spec.setContent(R.id.fragment3);
spec.setIndicator("boxing");
tab.addTab(spec);
spec = tab.newTabSpec("tab3");
spec.setContent(R.id.fragment4);
spec.setIndicator("cricket");
tab.addTab(spec);
spec = tab.newTabSpec("tab3");
spec.setContent(R.id.fragment5);
spec.setIndicator("base ball");
tab.addTab(spec);
tab.setCurrentTab(0);
}
screen shot....
You're already using a HorizontalScrollView for the TabWidget, so this is the correct way. If you're not able to scrool despite doing is this way, probably you're having a layout problem.
You didn't detail if you're using a custom layout for your TabWidget, but if not, this would be a good approach to achieve what you want, since there's not a method to say "I just want to show 3 tabs at a time".
Simply define a new layout for your tabs so the three together fit the screen's width, the rest will be reachable by scrolling.
---- EDIT ----
I see pretty much LinearLayouts in your code. Try something like this:
<LinearLayout
android:id="#+id/TabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="99"
android:orientation="vertical">
<TabHost
android:id="#+android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/TabLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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="wrap_content"
android:layout_height="wrap_content"></TabWidget>
</HorizontalScrollView>
<FrameLayout
android:id="#+android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
Related
I have this XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/blanco"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/verde_us" >
<ImageView
android:id="#+id/detalle_imagen_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:src="#drawable/icon_map" />
<View
android:id="#+id/View02"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#color/blanco" />
<TextView
android:id="#+id/text_nombre_empresa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="#string/text_noticias"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/blanco" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
But when I run the app the output is other.
Any help? Thanks!
I want the tabs below the text that says "Ahumadero" In the XML
Then stop using action bar tabs. Use some other sort of tabbed indicator for your ViewPager, one where you control the position by placing it in the LinearLayout yourself. There are many open source implementations, such as PagerSlidingTabStrip.
Because the information in each tab may not display depending on screen size, i have added a scrollview. The list view displays the information from the database alright but then it does not spread across the screen. It takes only a small portion of the screen and I can only scroll in that small portion. If i have 2 sets on information I expect to see two rows but I see just one and I can scroll within that to see the second set of information. But when i remove the scroll view my listview displays like it is supposed to but then the other tabs suffer because i cannot scroll to see the other fields.
Below is my main activity:
<TabHost
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"></TabWidget>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:fillViewport="true">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--Overview Tab Starts-->
<LinearLayout
android:id="#+id/overviewTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/displayListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!--Overview Tab ends-->
<!--Base Data Tab starts-->
<LinearLayout
android:id="#+id/baseDataTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp">
//the needed views go here//
</LinearLayout>
<!--Base Data Tab ends-->
<!--Task Tab starts-->
<LinearLayout
android:id="#+id/taskTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp">
//the needed views go here//
</LinearLayout>
<!--Task Tab ends-->
<!--Survey Tab starts-->
<LinearLayout
android:id="#+id/surveyTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp">
//the needed views go here//
</LinearLayout>
<!--Survey Tab ends-->
</FrameLayout>
</ScrollView>
</LinearLayout>
</TabHost>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="match_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="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Overview Tab Starts -->
<LinearLayout
android:id="#+id/overviewTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/displayListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- Overview Tab ends -->
<!-- Base Data Tab starts -->
<LinearLayout
android:id="#+id/baseDataTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
</LinearLayout>
<!-- Base Data Tab ends -->
<!-- Task Tab starts -->
<LinearLayout
android:id="#+id/taskTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
</LinearLayout>
<!-- Task Tab ends -->
<!-- Survey Tab starts -->
<LinearLayout
android:id="#+id/surveyTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
</LinearLayout>
<!-- Survey Tab ends -->
</FrameLayout>
</ScrollView>
</LinearLayout>
You had some problems with your layout_height and width attributes. I changed some of them, this should work ;-)
How to delete 2 point in bottom of tabhost
Please see below image to get more detail.
Thanks so much.
This is XML, I'm using default tabhost and i don't know why they appear
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginBottom="50dp">
<TabHost android:id="#android:id/tabhost"
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_gravity="top"
android:layout_marginLeft="-4dp"
android:layout_marginRight="-4dp"
android:layout_marginTop="37dp"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
style="#color/white"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</FrameLayout>
You're going to need to post the XML/Code you used to create this.
Not able to access view inside tabhost.
I want to access myTitle layout as well as myTitleText and change their attributes programatically.
tried using findviewbyid and view.findviewbyid but gets null.
tried inflator but attributes remain unchanged.
Please help
<?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" >
<LinearLayout
android:id="#+id/layout_myTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/title_myTitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE" />
</LinearLayout>
<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="0dip" android:layout_weight="1.0"/>
</LinearLayout>
</TabHost>
For those who are searching for a answer on how to access a view inside TabHost do the following.
Let you have an XML like:
<LinearLayout ...
<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:orientation="vertical">
<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">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Text 1 -->
<TextView
android:id="#+id/text1"
android:text="Some text 1"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Text 2 -->
<TextView
android:id="#+id/text2"
android:text="Some text 2"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
If you want to access text2, you should first access to a container (tab2).
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
public void onTabChanged(String tabId) {
Log.i(TAG, "tabId = " + tabId);
if (tabId.equals("tab2")) {
LinearLayout layout = (LinearLayout) findViewById(R.id.tab2);
TextView text = (TextView) layout.findViewById(R.id.text2);
}
}
});
done using tabHost
TextView tv = (TextView) tabHost.findViewById(R.id.title_myTitleText);
I have a TextView that is only supposed to show up on the first TabPage (which contains the ScrollView), but for some reason it shows up on both of my TabPages, whereas the TableLayout only shows up in the first TabPage like it should. I have no idea why...here is my XML file: The TextView in question is the 'primaryInfo' in the ScrollView.
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabcontent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Primary Info"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:gravity="center_horizontal"
android:id="#+id/piTextView"
android:background="#595959"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/specsTab"
android:layout_centerHorizontal="true"/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/photosTab">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/thumbnailGallery"
android:id="#+id/selectedPhoto"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageProgressLayout"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:indeterminate="true"
android:layout_marginTop="5dp"
android_layout_marginLeft="20dp"
android_layout_marginBottom="20dp"
android:id="#+id/galleryProgress"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/loadingTextView"
android:text="Loading images..."
android:layout_marginLeft="5dp"
android:layout_centerVertical="true"
android:textSize="13sp"/>
</LinearLayout>
<Gallery
android:id="#+id/thumbnailGallery"
android:layout_above="#+id/galleryProgress"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content"/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
edit
Tab setup code:
public void tabSetup()
{
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TextView tv1 = new TextView(this);
tv1.setText("Specs");
tv1.setHeight(50);
TextView tv2 = new TextView(this);
tv2.setText("Photos");
tv2.setHeight(50);
TabSpec spec1=tabHost.newTabSpec("Specs");
spec1.setContent(R.id.specsTab);
spec1.setIndicator("Specs");
TabSpec spec2=tabHost.newTabSpec("Photos");
spec2.setIndicator("Photos");
spec2.setContent(R.id.photosTab);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
}
Well, the problem was that when I changed the layout, I forgot to change the View that I passed into the setContent method since the top level view for that tab page changed. Here is what it was before I changed the layout (and it worked originally):
TabSpec spec1=tabHost.newTabSpec("Specs");
spec1.setContent(R.id.specsTab);
spec1.setIndicator("Specs");
and this is what it needed to be with the current layout that I posted above:
TabSpec spec1=tabHost.newTabSpec("Specs");
spec1.setContent(R.id.scrollView);
spec1.setIndicator("Specs");
Problem solved. Credit to Jack for getting me to post the code since that is when I finally noticed it ;)