I have a layout which contains a Tabhost. The tabs are at the bottom of the screen. The first tab starts an ActivityGroup. The first activity in that ActivityGroup contains a scrollview. When the contents are displayed in the scrollview and you scroll all the way down, the bottom of the scrollview is hidden behind the tabs. Any ideas how to fix this?
When I start the activitygroup, I use this code:
Window window = getLocalActivityManager().startActivity(pActivityClass.getName(), intent);
setContentView(window.getDecorView());
Is the decor view the entire screen? I just want the view to be the tabcontent.
Here is the main layout:
<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">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentTop="true"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</TabHost>
Here is the view I want in the tabcontent:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout android:id="#+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"/>
... a bunch of other components ...
</RelativeLayout>
</ScrollView>
Fix your layout so the content view fits above the tab widget, instead of filling the entire parent container, which tells it to lay out as the full size of the RelativeLayout and then lay the TabWidget on top. Something more like this:
<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">
<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"/>
</RelativeLayout>
</TabHost>
I also removed some of the unnecessary items like android:orientation which does nothing inside of a RelativeLayout.
HTH
Optimal result.
android:minWidth= Increase the value of...
<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" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
**android:minWidth="480dp"**
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="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#android:id/tabs"/>
Here, the key line is,
android:layout_above="#android:id/tabs"
I know there might be a "correct" way to do this, but I just added
<LinearLayout android:layout_width="fill_parent"
android:layout_height="50dp"></LinearLayout>
to the bottom of the xml file I was loading into the tab.
Also user1060374 is right the FrameLayout needs to be above the Tabwidget or the scrollview will hide(be on top of) the tabbar if the contents needs scrolled.
But just doing this won't answer your question, so I added the padding.
Related
When an Activity X is loaded into FrameLayout when tab is changed I want that X to be able access to tmp LinearLayout that is located outside of TabHost.
Assume that TmpActivity is loaded into FrameLayout when some tab was clicked, so in that activity I want do something like this
public void onCreate(Bundle savedInstanceState) {
LinearLayout ll = (LinearLayout)findViewById(R.id.tmp);
}
How I can do this?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tmp"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50px"
android:background="#00FF00">
</LinearLayout>
<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"
android:padding="5dp">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="500px"
android:padding="5dp"
android:background="#FF0000"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FF00FF" />
</LinearLayout>
</TabHost>
</LinearLayout>
You can get your parent activity from your activity loaded in your tab host frame layout. From there, you can access your linear layout throught a getter or a member variable located in your TabHostActivity.
I have been trying to develop an android app that contain an activity which is scrollable
and inside the activity, I have 2 textView which I want them to be scrollable as well.
My problem is that
whenever I touch inside the textView the scrolls show up but the main activity part which is the linearLayout directly steel the focus and no longer the textView scroll
the way I have it now is setup for the textView to scroll in the xml file I have done that.
and if I keep raising my finger and put it back on the screen trying to scroll the textView I can move a little bit but as I said, the layout that contains the textView capture the focus and leave me unable to scroll the textView.
I hope I did explain my problem very well.
Please any suggestion to help.
let me explain how the app is built first
first part is: the main(first) activity is a tabHost
which I defined as scrollable
<?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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</ScrollView>
</TabHost>
where I am having problem with is this activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/light_gray_color"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/linearLayout3"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/black_color"
android:layout_gravity="center_horizontal"
android:text="#string/display_label"
android:id="#+id/display_label">
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.83"
android:baselineAligned="false"
android:orientation="horizontal" >
<ScrollView
android:id="#+id/english_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_english_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
<ScrollView
android:id="#+id/translation_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_translation_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
</LinearLayout>
</LinearLayout>
I guess you should cut <ScrollView> out of the first 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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</TabHost>
My understanding is that you have a vertically scrolling activity, which contains two vertically scrolling text views? If so, you can't do it. Its not just a poor design choice, its literally impossible to tell which view the user intends to scroll when they make swipe motion. You can have horizontal scrolling inside a vertically scrolling view, or vice versa. You can't have horizontal scrolling inside horizontal scrolling or vertical scrolling inside vertical scrolling.
I believe this is mentioned in the listview talk in the 2010 google io conference: http://www.youtube.com/watch?v=wDBM6wVEO70
I am trying to get an AdView directly below a TabHost. RelativeLayout does allow this to happen with android:layout_alignParentBottom="true" however this overlaps TabHost contents, and does so for the ScrollView's I add inside each Tab (this would probably occur for any views whose height was large enough)
Right now the closest I can get to having a TabHost and AdView in their own seperate space on the screen is using this code (below), that allows me to have a Ad directly above the TabHost...so close, any ideas?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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" >
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="####"
ads:loadAdOnCreate="true"
ads:testDevices="####" />
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
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" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
You should make the tab host to fill the remaining space after the adview like
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0">
Now the tab host will take the remaining space after the adview.
Hey, I have a TabHost with two tabs, each with an Activity.
The first is an Activity that has a normal textView.
The second tab is a ListActivity with a ListView.
All this works fine.
However, I want to add another listview BELOW the TabHost.
So Basically I would have:
Tab Buttons
Tab Content (The Activity: Text or List)
ListView
My main.xml:
<?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"
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>
<ListView android:id="#+id/footerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
However, I'm really not sure how to set the data for the footer list.
An activity using a ListView needs to extend ListActivity...
But my main Activity extends TabActivity so I'm not sure how to fill in the list data since I can't use ListAdapter without extending ListActivity.
Anyone know a solution?
Fixed.
I used a RelativeLayout instead of ListLayout
My final XML (if useful to anyone):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footerlist"
android:layout_alignParentTop="true">
<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:paddingTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
</LinearLayout>
</TabHost>
<ListView android:id="#+id/footerlist"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
An activity using a ListView can be a simple Activity, not only ListActivity. So, just add to your xml layout under the </TabHost> your ListView. Btw, TabHost can be included in an ordinary Activity instead of TabActivity too.
I have a screen that uses tabs in my android application. There is a line (like a border) that shows between the tabwidget and the framelayout. I want to get rid of that line, but cant seem to find what it is. I have determined that it is part of the FrameLayout by setting its visibilty to gone. Please refer to the code 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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fb8c10"
>
<ImageView
android:id="#+id/img_confirm_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/confirm_header"
/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dip"
android:background="#fb8c10"
android:tabStripEnabled="false"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/tab_bg"
/>
</LinearLayout>
</TabHost>
This is a link of the current layout and what I'm trying to do
http://img441.imageshack.us/g/screenshot20110116at513.png/
The orange layout is my app, and the gray is what I'm trying to do.
Notice how in the gray screenshot the tab flows into the frame.
Apologies for the links, I can't post images yet :p
Thanks!
I managed to solve this by manipulating the z-index using relative layout. I was able to position the tabs slightly over the frame layout. Refer to code 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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fb8c10"
>
<ImageView
android:id="#+id/img_confirm_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/tab_header"
/>
<RelativeLayout
android:id="#+id/widget77"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:layout_marginTop="33dip"
/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fb8c10"
android:tabStripEnabled="true"
android:layout_above="#android:id/tabcontent"
android:layout_marginBottom="40dip"
/>
</RelativeLayout>
</LinearLayout>
</TabHost>
Just now I came across this issue. However, I also tried to remove the top border of FrameLayout. I did it. but I don't think it is a way to remove the top border. anyway FYI,
Just place an TextView with background white on Border and use AbsoluteLayout.
Eg:
<AbsoluteLayout>
<TabHost
android:layout_x="0dip"
android:layout_y="5dip" ...>
<AbsoluteLayout android:padding="5dip" android:background="#ffffff">
<TabWidget/>
<FrameLayout ....
android:layout_x="0dip" android:layout_y="65dip" />
</AbsoluteLayout>
</TabHost>
<TextView
android:layout_width="fill_parent" android:layout_height="25dip"
android:layout_x="0dip" android:layout_y="65dip"
android:background="#ffffff"/>
</AbsoluteLayout>