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.
Related
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="80.0dip"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="1.0dip"
android:paddingTop="1.0dip"
android:scrollbars="none" >
<include layout="#layout/quickactions_buttons_part" />
</HorizontalScrollView>
</LinearLayout>
but I get this warnings
This LinearLayout layout or its FrameLayout parent is useless; transfer the background attribute to the other view
and
This HorizontalScrollView layout or its LinearLayout parent is useless
Does anyone have any idea what can i do that this message wil go away?
You have a single component (row) vertical linear layout, containing another linear layout. This does not make any sense as layout is a container for the multiple components. If there is only one component, such container is redundant and can be replaced directly by the single component it holds.
Same way, the second LinearLayout also makes no sense, holding a single component, the HorizontalScrollView. The only thing may matter there is the "80.0dip" property that needs to be specified on the component now.
Hence your layout is unnecessary sophisticated. The contents of the FrameLayout can be rewritten simpler as
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="80.0dip"
android:paddingBottom="1.0dip"
android:paddingTop="1.0dip"
android:scrollbars="none" >
<include layout="#layout/quickactions_buttons_part" />
</HorizontalScrollView>
resulting the code that both runs faster and is easier to understand.
I think it is due to FrameLayout, 1st LinerLayout and 2nd LinearLayout which are not solving any purpose while you have everything inside HorizontalScrollView.
I keep browsing different posts and they all have the footer try to stay on the screen.
But I want the footer to appear on every page. Some of my pages do not have a scroll, but some do. Whenever there is a scroll, I would like the footer to appear below the scroll. How can that be done?
For example, if I have this page:
<?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"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/page_exlain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some text that either extends far down or is pretty short."
android:layout_marginTop ="20dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
What is a good way to add a footer to this that does not necessarily appear above the fold?
Thanks!
My way of doing this is by having two linear layouts inside the parent layout. The first one is what I call the content area and will have a weight of 1, meaning it will try to take as much space it can from the parent view. The footer layout on the other hand will have no weight and will therefor remain with a height matching the content inside even if the other view (the content area) is empty.
You can add a scrollview or any other type of layout inside the content part of this layout without breaking the disposition of the two elements and without needing to worry about the position of the footer since it will always be at the bottom of the screen.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
With a little content added to the prior code, you end with something like this, note that it's extremely simplified. You'll have no issues modifying it to your needs as long as you understand the weight property in place.
You just need to treat the "content" LinearLayout as if it was the parent one, inserting scrollviews or whatever your needing and forgetting about the footer. Note that if the footer is recursive, meaning you are going to be using it multiple times, you could load it in the xml directly without copying it in to all your layouts
<include layout="#layout/footer" />
Where #layout/footer is an xml file in your layouts folder with the content of the footer that you want to reuse. This is virtually the same as adding it manually but with the convenience of not having to maintain it across several files.
Hope I was of help.
I am putting more than 15 buttons in one .xml file. But it seem only to be displaying the top 9 of them ? Why aren't the other buttons showed or can't I scroll down to see them?
I am using a LinearLayout with tags.
Are you using a LinearLayout perhaps to contain the buttons? Or any other layout that's not contained in a ScrollView? Good chance your buttons are being drawn, they are just outside your screen.
Wrap your layout in a ScrollView like so:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- your buttons here -->
</LinearLayout>
</ScrollView>
This makes your layout scrollable, so you will be able to just scroll down and see your buttons.
Did you use this?
android:orientation="vertical"
Please post your code,
Are you wrapping everything is ScrollView?:
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ScrollView>
More info http://developer.android.com/reference/android/widget/ScrollView.html
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.
I used the tabhost tutorial to get started with the Tabhost control.
After some play around I wanted to make the tabhost scrollable, which I figured out.
Now I want the tabhost at the bottom of the display which is just not working for me.
Switched to Relative Layout which was suggested here: iPhone-like Tabbar
My code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal" android:isScrollContainer="true">
<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:layout_alignParentBottom="true">
<RelativeLayout android:layout_height="fill_parent"
android:layout_width="fill_parent">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="none"
android:layout_alignParentBottom="true">
<TabWidget android:id="#android:id/tabs"
android:layout_alignParentBottom="true" 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"
android:padding="2dp" />
</RelativeLayout>
</TabHost>
I need a hint why it's not working / how this would work. I tried with relative layout and layout_alignParentBottom="true" now it's there a few times (in the HorizontalScrollView and the TabWidget)
Thanks to Arve leading me to "custom controls" I found a promising project:
https://github.com/honcheng/ScrollableTabHost-for-Android
I hope some others looking for this kind of tabhost can use it :)
A possible library to help you do this:
http://code.google.com/p/androidtabs/
From their project description:
Due to limitation of Android Tab component I created a custom TabWidget that I am using in couple different projects already. The widget allows us to add custom background and use custom icons, tabs can be Top/Bottom aligned.
EDIT: I have not tested this myself, but it looks promising.