Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old November 24th, 2011, 03:22 AM   #1 (permalink)
New Member
 
Join Date: Nov 2011
Posts: 7
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default MotionEvent and relative layout

I have a relative layout built from XML.
I am capturing the onTouchEvent.
When I touch the screen anywhere except over the TableLayout or ImageButton
the MotionEvent.ACTION_DOWN and MotionEvent.ACTION_MOVE
events work fine.
Any suggestions as to how to make the onTouchEvent() work on the TableLayout
and ImageButton views?

The purpose of the exercise was to have a drag method working over the relative layout,
nothing I have read suggests it is possible unfortunately.
Maybe manipulating the layout_margin values?
I was contemplating a transparent canvas overlay but haven't figured that out yet.

Code snippets below

XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:background="@drawable/yellowbackground">
<ImageButton
android:id="@+id/back_butt"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_width="40dp"
android:layout_height="36dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:clickable = "true"
androidnClick="additionClickHandler"
android:src="@drawable/back_button"
android:background="@null"
></ImageButton>
<ImageView
android:id="@+id/r2c2"
android:layout_centerInParent="true"
android:layout_width="55dp"
android:layout_height="55dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/four"
android:background="@null"
>
</ImageView>
.....more image views here
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
>
<TableRow>
<ImageView
android:id="@+id/imageB1"
android:maxWidth="47dp"
androidadding="1dp"
android:layout_width="wrap_content"
android:layout_height="47dp"
android:clickable = "true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/one"
android:background="@drawable/buttonbg"
></ImageView>
<ImageButton
android:id="@+id/imageB2"
android:maxWidth="47dp"
..........
android:src="@drawable/two"
android:background="@drawable/buttonbg"
></ImageButton>
<ImageButton
android:id="@+id/imageB3"
android:maxWidth="47dp"
..............
android:src="@drawable/three"
android:background="@drawable/buttonbg"
></ImageButton>
</TableRow>
</TableLayout>

</RelativeLayout>

JAVA

@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();

// Remember where we started
mLastTouchX = x;
mLastTouchY = y;
Log.d(TAG, "Coords: x=" + x + ",y=" + y);
break;
}

case MotionEvent.ACTION_MOVE: {
final float x = ev.getX();
final float y = ev.getY();
Log.d(TAG, "moved to: x=" + x + ",y=" + y);

Any help would be great.

spikey100 is offline  
Last edited by spikey100; November 24th, 2011 at 04:46 AM.
Reply With Quote
Sponsors
Old November 26th, 2011, 03:45 AM   #2 (permalink)
New Member
 
Join Date: Nov 2011
Posts: 7
 
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Any help?
spikey100 is offline  
Reply With Quote
Old November 28th, 2011, 07:07 AM   #3 (permalink)
Member
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 134
 
Device(s): SE Xperia X10
Thanks: 2
Thanked 22 Times in 22 Posts
Default

It might have something to do with the way Android handles touch input. Simply put, some view can consume the event, without passing it on. This becomes a problem if you have different views on top of each other, that all need to register and handle the touch event.

First thing you should try is to explicitly handle all touches in all the views that get touches and simply implements their onTouch method to return false, which means that the view does not want to handle that specific touch event id, and that it should be passed on. Returning true, means that the view consumes the event - handles it and does not pass it on.

Try that, for a start...
JamTheMan is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:49 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo