Prevent ImageView from receiving touch events when scrolling - android

I'm making an app with lots of ImageViews and I needed to attach a touch listener in some of them. While doing this, I encountered a problem. If the pointer was held down at the location where the ImageView with touch listeners attached to it and was about to produce a scrolling event, there seems a fighting scene between the Views and the ScrollView in w/c where the event was actually occured and in w/c the event is supposed to belong. The screen scrolls in a fast rate then return where the first pointer was touched down, so it means it is an unwanted behavior.
Setting an onTouchListener in the ImageView makes the scrolling uneasy and unwanted, how do I prevent ImageView from receiving touch events when scrolling?
Some of the codes
Layout: act_map_view.xml
<?xml version="1.0" encoding="utf-8"?>
<com.nkraft.mobiletomblocator.CustomVScroll
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" >
<com.nkraft.mobiletomblocator.CustomHScroll
android:id="#+id/hScroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none" >
<com.nkraft.mobiletomblocator.CustomGridLayout
android:id="#+id/map_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</com.nkraft.mobiletomblocator.CustomGridLayout>
</com.nkraft.mobiletomblocator.CustomHScroll>
</com.nkraft.mobiletomblocator.CustomVScroll>
Notes:
The GridLayout is populated with ImageViews at runtime.
I customized my horizontal and vertical ScrollView so that I can scroll in both directions concurrently i.e diagonal scrolling

From the notes I've mention, I figured a clue from the problem I'm currently facing. I think this issue had been thought before the standard android's scrollbar was implemented. The main reason this occurs to me is that I extended the class of the scrollbars and totally replacing the default behavior of it. So for me to achieve what I want (the scrollbar with diagonal scrolling) I follow this post and replace both my vertical and horizontal scrollview with this TwoDScrollView, also thanks for this post directing me to it.

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.

How do I give a gridLayout the ability to scroll vertically and horizontally at the start of the application in android?

So imagine a view with 9 tiles that looks something like this:
(tile1) (tile2) (tile3)
(tile4) (tile5) (tile6)
(tile7) (tile8) (tile9)
One tile takes up most of the screen. I have this set up already with a horizontalscrollgroup nested inside a scrollgroup to enable both horizontal and vertical scrolling but the problem is that the view starts off with tile1 in the center of the screen. I want the view to start off with tile 5 in the center and give the user the ability to scroll up, down, left, right, and diagonally. How can I implement this?
I guess my main issue is centering the view on tile5. Also is this is a good way to implement both horizontal and vertical scrolling or is there a more proper way of doing this?
Sorry I'm a beginner with mobile ui programming.
Try this :
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
</HorizontalScrollView>
</ScrollView>

scrolling the background image in android java while adding a view to screen

I want to scroll the background in android. I have a scrollview which has many views. I need to implement a way wherein i need to scroll only the background while adding the views. I came across many forums but none of them are very clear. Please give an idea or references to implement it. To give more idea for what i am looking for is, Just consider a bike game wherein the background road image moves while riding the bike. I just need similar implementation while scrolling the screen.
Maybe you could do like this:
RelativeLayout as the parent
ScrollView with your image set as background
Then the other views, but outside of the ScrollView and inside of the RelativeLayout.
EDIT:
<RelativeLayout
android:id="#+id/relParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<OtherViews />
<ScrollView
android:id="#+id/scrlParent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/yourbackground">
</ScrollView>
</RelativeLayout>
I think that something like this might work. You see, the RelativeLayout is the parent. Then comes your other views, on the top of your ScrollView. Then, after your other views tag, comes the ScrollView, with only a background. I'm not sure if a background tag would work, so maybe you should remove the android:background="#drawable/yourbackground" and put an ImageView inside of the ScrollView.

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"

Android ViewFlipper + Gesture Detector

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

Categories

Resources