I have a tab host in which i have more than 6 buttons. However the screen shows only 3-4 buttons.
Following is the code which i am using along with the image.
<?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="#777777">
<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:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#drawable/navbar_background"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#+id/layTab"/>
</RelativeLayout>
</TabHost>
The question is, How am i suppose to add a scroll so that i can scroll upto all 6 buttons or any other trick.
Best Regards
Just nest the TabWidget inside a HorizontalScrollingView, like 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"
android:background="#777777" >
<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:background="#drawable/navbar_background"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<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>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/layTab"
android:layout_alignParentTop="true" />
</RelativeLayout>
</TabHost>
By the way, this solution works for many other scenarios, RadioGroup, for example
Related
I am having a linearlayout and scrollbar. I am trying to have button below the scrollbar.
Can you please suggest what I am doing wrong here.
Here is my XML code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="#+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
<Button android:id="#+id/next_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="#android:color/background_light"
/>
</LinearLayout>
Thanks,
Aman
By setting ScrollView weight to 1 and height to 0dp it will wrap its height to fill all the space left after the Buttongets layouted to use wrap_content height:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TableLayout
android:id="#+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
<Button
android:id="#+id/next_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="#android:color/background_light" />
</LinearLayout>
add
layout_weight
parameter to each part( i added 90% scrollview 10% button)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="9" >
<TableLayout
android:id="#+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
<Button android:id="#+id/next_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="#android:color/background_light"
android:layout_weight="1"
/>
</LinearLayout>
You should use Relative layout in place of LinearLayout. That will solve some problem
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/next_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:layout_alignParentBottom="true"
android:textColor="#android:color/background_light"
/>
<ScrollView
android:id="#+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/next_btn" >
<TableLayout
android:id="#+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TableLayout>
</ScrollView>
</RelativeLayout>
I am using android:layout_alignParentBottom="true" to align at parent bottom but for this particular case is not valid. Parent is a relative layout that has fixed size and bigger that screen height. Now I need to place a textview aligned at bottom of screen and not parent bottom. How to reach it? thank you.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="600dp" >
<RelativeLayout
android:id="#+id/blogLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="#+id/webviewBlog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#android:color/black"
android:scrollbars="none"
android:fitsSystemWindows="true" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Volver"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<TextView
android:id="#+id/Volvertxt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Volver"
android:textColor="#android:color/white"
android:textSize="30px"
android:gravity="center"
android:clickable="true"
android:onClick="onClickVolver" />
</RelativeLayout>
</RelativeLayout>
I have modified your code hope it solves your problem
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/webviewBlog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#android:color/black"
android:scrollbars="none"
android:fitsSystemWindows="true" />
<TextView
android:id="#+id/Volvertxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Volver"
android:textColor="#android:color/white"
android:textSize="30px"
android:gravity="center"
android:clickable="true"
android:onClick="onClickVolver" />
</RelativeLayout>
That is because, you are giving height in dp units of the parent layout. Make it match_parent.
EDIT:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="#+id/webviewBlog"
android:layout_width="fill_parent"
android:layout_height="600dp"
android:textColor="#android:color/black"
android:scrollbars="none"
android:fitsSystemWindows="true" />
<RelativeLayout
android:id="#+id/Volver"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<TextView
android:id="#+id/Volvertxt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Volver"
android:textColor="#android:color/white"
android:textSize="30px"
android:gravity="center"
android:clickable="true"
android:onClick="onClickVolver" />
</RelativeLayout>
</RelativeLayout>
I am sure it needs a simple flag but I am not finding the correct one, spent at least 2 hours to find a correct solution. Hope to get help from you guru's.
I am trying to create a two tab layout using fragmentActivity. I want to give 50% screen space to each tab. I am able to do that (see attached Screen shot) the next hurdle is I want the tab header e.g. Financial with black bkg should take 50% and Others with gary bkg to take remaining 50%.
I hope I am clear with my question. :-)
attaching my 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"
android:background="#EFEFEF" >
<RelativeLayout
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:gravity="center_horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#+id/financial"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"
android:tag="#string/financial" />
<FrameLayout
android:id="#+id/other"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:tag="#string/others" />
</FrameLayout>
</RelativeLayout>
</TabHost>
**The calling xml would be**
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1" >
</ListView>
<fragment
class="com.......android.activity.AccountsTab"
android:id="#+id/tabs_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
adding tab.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="#dimen/tab_height"
android:background="#drawable/tab_selector"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="#dimen/tab_padding"
android:weightSum="0.5" >
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal|center_vertical"
android:textColor="#drawable/tab_text_selector"
android:textSize="#dimen/text_default"
android:textStyle="italic" />
</RelativeLayout>
I think you should do it like this.
<?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>
With this you can add as many tabs as you want.
Hope you want this.
I have tabHost positioned at bottom of view and tabHost strip appears also at bottom of taps. I would like to get strip positioned on top of tabs. How to do it? Here is my xml file. Thank you.
<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" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</TabHost>
Try With 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: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>
I am using a HorizontalScrollView inside a RelativeLayout. It works fine on a 1.6+API, but on 1.5 API the HorizontalScrollView does not scroll, what is the problem?
On 1.5 API (3) you can only see the first part of the HorizontalScrollView and there's no scrolling at all, while it seems to work fine on API4 and above.
To answer question, here's some code used:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="#+id/pscroll"
android:scrollbars="horizontal"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/ad"
android:fillViewport="true"
android:scrollbarAlwaysDrawHorizontalTrack="true">
<LinearLayout android:orientation="horizontal" android:id="#+id/LinearLayout01" android:scrollbars="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="#+id/P1" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageButton android:id="#+id/P2" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
Edit: refined, based off of negative feedback (apparently people expect their hand to be held through this)
A scroll view is meant to contain a layout, not the reversal of that. Therefore your layout should be:
<HorizontalScrollView android:id="#+id/pscroll"
android:scrollbars="horizontal" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/ad" android:fillViewport="true"
android:scrollbarAlwaysDrawHorizontalTrack="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:id="#+id/LinearLayout01" android:scrollbars="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="#+id/P1" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton android:id="#+id/P2" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</HorizontalScrollView>