I have a little problem with a ScrollView. I have a layout for an activity which is made with a ScrollView. This scrollview contains two ListViews.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootViewGroup" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="vertical">
<LinearLayout android:orientation="vertical"
android:gravity="top" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#drawable/cmb_bg">
<ListView android:id="#+id/accountsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="none" />
<ListView android:id="#+id/cardsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="none" />
</LinearLayout>
In the onCreate method of my activity I compute ListViews height according their contents.
During execution, on activity launch, ScrollView is already scrolled a bit.
So I tried, at the end of onCreate to call method scrollTo(0, 0), but it does not change anything.
Any ideas?
AHHH!!! Remove ScrollView and leave only ONE ListView in your activity. It's not intended to work this way
.If you want to have different content in your ONE listView - modify your adapter, or change the UI
But never, ever put different scrollable containers on the same screen/inside each other
here is a related post.
http://groups.google.com/group/android-developers/browse_thread/thread/e7c8df374fe31733#
In theory you can slap two listview on the screen, but expect things to be weird. And i would really redesign it with with either separators or expanders or just with one ListView.
Related
I have what I thought would be straight forward to implement: A linear layout with two ListViews, both with a layout_weight="1". The first one is "fill parent" and the second one is "wrap content". The idea is that the first ListView is to occupy the entire screen when the second ListView is empty, and when both had entries the screen would be shared. Well, it almost works but when the second ListView is empty, the first ListView scrolls down only half-way through the LAST entry. The remainder of the last entry is off the screen. Does anyone understand why that is the case?
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/dots"
android:layout_width="match_parent"
android:layout_height="24dp" >
</LinearLayout>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/lni_logo" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="none"
android:transcriptMode="alwaysScroll"
android:layout_weight="1"
android:id="#android:id/list" >
</ListView>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="none"
android:transcriptMode="alwaysScroll"
android:layout_weight="1"
android:id="#+id/rtsalist">
</ListView>
</LinearLayout>
Actually at this stage I have not made an adapter for my second ListView so I have not been able to test it with entries in it. But the point is that it should be as if I did not have the ListView at all when it is empty. Alas such is not the case. When I remove the second ListView, the first one scrolls down to the last element correctly, displaying the entire entry.
Thanks for any insight!
Put in a line like android:paddingBottom="20dp" into your top ListView. Adjust the 20dp value until it looks the way you want it to. You can programmatically change the bottom padding as the list disappears and reappeares to make it look just right.
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 have a GridView that displays items, each item is a ListView.
the problem is that I can't scroll the ListView items, seems like the GridView is obtaining the focus or preventing it from the ListViews
is there a workaround for this ?
thanks
**
EDIT:
**
here's my activity layout
<GridView
android:id="#+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="35dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="300dp"
android:stretchMode="columnWidth"
/>
</LinearLayout>
each gridview item has the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/list"
/>
</LinearLayout>
set attribute android:scrollingCache="true" in your ListView
<ListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollingCache="true"
android:layout_weight="1" />
You cannot have a scrollable child view within a parent view that is scrollable. Google does not recommend it... and it's really messy. Read this
There have been people who've been trying to do a workaround (which doesn't look pretty), but I doubt it will work for you. But you can read it anyways and see if you can make it work for you. Enjoy.
One of the main reasons why it wont work is because of the way scrollable views handle touch. There's a method called dispatchTouchEvent() and onInterceptTouchEvent() that decides whether to intercept the touch event or pass it to it's children. For scrollable views, they will always intercept "swipe" movements. So it will never go to your children.
You can try to modify it, but if you think about it, how will you know if you're trying to scroll the parent or if you're trying to scroll the child? Imagine if the one of your scrollable children ends up taking the width of your screen, but then you want to scroll your parent, how will you manage that?
Summary:
it's not recommended .... if you really insist... then go ahead and write your own custom view to handle the logic. But i guarantee you it wont be pretty and will almost never work for all use cases.
when I turn the phone and the screen is rotating I cannot see the whole screen anymore. This is ok but I cannot scroll! Do I have to set some flag or property for scrolling? This is part of my xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*">
...
</TableLayout>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
...
</TableLayout>
</LinearLayout>
Thanks!
You have to put your complete layout inside a ScrollView in order for it to scroll.
It scrolls if your layout height is more than the screen height, which happens generally in landscape mode.
In your case put the LinearLayout inside a ScrollView, since ScrollView can only have 1 child.
You must know that in order to use an scrollView , you must put only one component inside (maybe a linearLayout) .Maybe that's your problem if you are trying to put in more components at that level.
I create a listview and that listview has a header. I use addHeaderView() method. But when i scroll down in listview the scrollbar vanishes. Is there any way to avoid this i.e i want to show the header all the times, if scrolled still it will show.
To do that you can't do that with the addHeaderView() method.
If you want to place a header on top you should place that in the layout, something 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" >
<TextView
android:id="#+id/titleBarText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
The widget is behaving as intended. For what you need, you need to create a relativelayout with TextView at top followed by listview. The textview would act as the header and be static irrespective of your scroll.