Android ViewFlipper + Gesture Detector - android

I am using gesture detector to catch "flings" and using a view flipper to change the screen when this happens. Some of my child views contain list views. The the gesture detector wont recognize a swipe if you swipe on the list view. But it will recognize it if it is onTop of TextView's or ImageView's. Is there a way to implement it so that it will recognize the swipes even if they are on top of another view that has a ClickListener?

Thank you for your answer. In order to get it working how I wanted it to all I had to add was this:
myList.setOnTouchListener(gestureListener);
for each of my lists. Now they correctly recognize horizontal swipes to change views, and vertical movement for scrolling the list.

An example from here: http://android-developers.blogspot.com/2009/10/gestures-on-android-16.html
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gestures"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="true"
android:orientation="vertical">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.gesture.GestureOverlayView>
I used this tutorial to look at Android's gesture overlay view. The example which this comes from has a ListView utilizing this GestureOverlayView to scroll the list.

There is another wonderful solution at android-journey.blogspot

Related

Delegate some touch events to children?

I have a vertical layout (it fills the screen) that when simplified, looks like this:
<LinearLayout android:orientation="vertical" >
<ImageView />
<EditText />
<ListView />
</LinearLayout>
The user can scroll this up and down, revealing more or less of the ImageView. But if I use a GestureDetector to interpret scroll, I don't know how to delegate some of them to the children. Especially so that if the user touches the ListView, it should first slide up to hide the ImageView completely, and only after that the ListView should scroll to the end.
My app supports 4.2 and higher.
The solution is based on StickyListHeaders. I put ImageView as header view of the list, and the EditText as sticky header. Now the ListView handles the touch events for me.

Using ScrollViews layout into HorizontalScrollView

I want to create a sort of card layout with cards that contain a ListView layout inside a HorizontalScrollableView that can scroll the cards horizontally. Everything is working but I have problem with scrolling. I can scroll the listview vertically only if I am not scrolling the cards horizontally and viceversa.
This is the main container:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<HorizontalScrollView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ddd" >
<LinearLayout
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
I inflate and add the listview items to the linear layout.
I would like to allow vertical and horizontal scrolling smoothly without these kind of limitations (simultaneous horizontal and vertical scrolling).
How can I achieve this?
Check out this, might help you implement custom two-way scrolling layout.
https://github.com/ened/Android-Tiling-ScrollView/blob/master/src/asia/ivity/android/tiledscrollview/TwoDScrollView.java
If you want any of ListView features though (like view recycling, filtering, adapters) - things are going to get more complicated.
I would suggest you to take ViewFlipper to give scroll effect horizontally. Then add ListView to flipper as a child. Use gesture to move it right and left.
ListView will still scroll vertically and if you are not able to set OnItemClickListener to ListView then you can use SingleTap method of Gesture.
ListView inside View flipper discussion 1 and ListView inside View Flipper Discussio 2
I would suggest having your horiziontallayout as the root view you return in getView() in you adapter. That way each row will scroll separate from each other. If that doesn't work right away you may have to setItemsCanFocus(true) for your rows to give the input to your horizontalscrollview.

Scrollbar does not scroll while using dynamically filled listview

I am not able to scroll in a scrollview which contains a listview and is filled dynamically as I get data from the webservice.
I am able to do scrolling in emulator through mouse wheel, but in avtual device I can not scroll the list.
The attributes of scrollview are
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:fillViewport="true"
android:orientation="vertical"
android:padding="6.0dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="5000"
android:scrollbarSize="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="2dp" >
<ListView
android:id="#+id/listbox_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="599.84"
android:minHeight="250dp" >
</ListView>
</LinearLayout>
</ScrollView>
Please help me soon
by just looking at the layout_width and layout_height of your elements, it's clear that your scrollview will not scroll. unless you have a fixed height listview, never put a listview inside a scrollview (or in this case, a listview inside a layout that sits inside a scrollview).
I don't have any links to back this up right now, but it's not possible, and a well-known 'problem'. If you google a bit, or search here on SO, you'll find a number of topics covering this.
The problem arises in most cases when you have a scrolling view inside another scrolling view in the same direction. Consider the following example:
You have Two lists inside of a ScrollView.
Both lists are exactly one screen tall.
How do you scroll down to the second list?
When scrolling, how will your layout know if you are scrolling the list or the container?
This is basically the question that is the cause, and the only official solution is that it is as it should be, and there won't be a fix. Usually it is enough to have either a ListView or a ScrollView, but I have faced cases when you must have a listview in a scrollview (in my case a client wanted an iPhone-like datespinner in a scrolling page).
I solved it by using a FrameLayout, containing a custom ScrollView, and a ListView on top of that. Then in the code for the custom ScrollView, I added a line in the onScroll method that updated the top margin of the ListView, to psuh it upwards or downwards as the user scrolled. Surprisingly it worked.
NOTE: remember that:
The ListView handles its own scroll. If all you need is a scrolling
list, you do not need a ScrollView.
If you need a layout with a list and space for buttons or other
views, consider creating your layout so that the list only covers
enough space for you to fit your other views below/above without
scrolling.
Add following in your linear layout
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"

Add OnGestureListener to Button?

I'm trying to figure out how to add an OnGestureListener or some other way to detect a touch drag across the screen to a button, or some other widget that can be added to a View. I've been trying to figure out how to do this for a while and I can't. I've seen and successfully been able to do it to an activity. Can anyone spell this out for me, because I seem to be having a lot more trouble than I thought I would with this. Thanks.
I'm assuming you've already gone through http://developer.android.com/resources/articles/gestures.html. The trick is that you can have the GestureOverlayView as a transparent layer on top of another View. You can then interpret any gestures detected as belonging to the underlying View.
In the article, they show you a layout like this:
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gestures"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="true"
android:orientation="vertical">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</android.gesture.GestureOverlayView>
Any gestures detected could then be interpreted as coming from the ListView. In your case replace the ListView with your Button, and you should be all set.
It sounds like you should be doing dragging and dropping,
http://developer.android.com/guide/topics/ui/drag-drop.html

How can I make horizontally scrollable items in a vertical listview?

I would like to use horizontall scrolling items in a vertically scrolling Listview.
My naive take on this was to put the contents of the listview items inside a scrollView. The items are wider horizontally than the scrollview, but not higher than the scrollview. Since the listview is a normal vertically scrolling listview, I figured that dragging vertically would scroll in the list, while dragging horizontally would scroll in the items.
However that didn't work. The list scrolls fine vertically and shows the items correctly, but scrolling horizontally does not work (nothing happens). Unfortunately I am really not sure where to go from here.
Note that the items should scroll horizontally independently of the other items, i.e the whole list should not scroll sideways when dragging sideways.
As a reference, I would like the list to behave similar to what it does in the app 'Pulse', in case you have seen it.
Make ordinary ListView with any adapter you like but design the item Layout something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:id="#+id/hor_scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/lin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6.0dip"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:focusable="false" />
<TextView
android:textAppearance="?android:textAppearanceMedium"
android:gravity="center_vertical"
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:layout_toRightOf="#id/icon"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
You'll have Vertically Scrollable ListView with Horizontally Scrollable items. And the items are scrolled independantly from other items.
You need to use a HorizontalScrollView. Droidstack is an open source app (I wrote) that does just this (in the questions lists you can scroll the tags on each question), if you want a concrete example.
if you follow the good practices of android development, you should never put a ScrollView inside a ListView, is unrecomended bu Romain Guy and other people from android development, to read the arguments read here: Android ScrollView layout problem
from the android docs:
"You should never use a HorizontalScrollView with a ListView, since ListView takes care of its own scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by HorizontalScrollView."
EDIT: it seems that the warning posted above is an error from the android documentation, talking with some colleagues they told me its possible. The issue in the documentation is here, http://code.google.com/p/android/issues/detail?id=2781.
my appologies
You can use "ViewPager" each element in the list can be a ViewPager

Categories

Resources