Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:52:05+00:00 2026-05-17T22:52:05+00:00

I have custom view in a HorizontalScrollView wrapped in a ScrollView and I want

  • 0

I have custom view in a HorizontalScrollView wrapped in a ScrollView and I want to act on ACTION_UP in onTouchEvent when the touch point has been moved but no scroll has been done, i.e. when the view is smaller than or equal to the window size. A single touch without move gives ACTION_UP as it should.

When running the (following) code under 2.1 I get ACTION_UP as expected. When running the same code on 2.2 I do not get the ACTION_UP (I have tested with both SDK 2.1 and 2.2 on the 2.2 emulator).

Have I accidentally used a “bug that works” in the 2.1 version and has been fixed for 2.2 or is this a new error? Is there a workaround?

See the following logcat:

2.1
I/CustomActivityView(  225): ACTION_DOWN at 307.000000,
I/CustomActivityView(  225): ACTION_MOVE at 297.000000,
I/CustomActivityView(  225): ACTION_MOVE at 292.000000,
I/CustomActivityView(  225): ACTION_MOVE at 290.000000,
I/CustomActivityView(  225): ACTION_MOVE at 289.000000,
I/CustomActivityView(  225): ACTION_MOVE at 286.000000,
I/CustomActivityView(  225): ACTION_UP at 286.000000,

2.2
/CustomActivityView(  279): ACTION_DOWN at 249.000000,
/CustomActivityView(  279): ACTION_MOVE at 249.000000,
/CustomActivityView(  279): ACTION_MOVE at 249.000000,
/CustomActivityView(  279): ACTION_MOVE at 249.000000,
/CustomActivityView(  279): ACTION_DOWN at 198.000000,
/CustomActivityView(  279): ACTION_MOVE at 199.000000,
/CustomActivityView(  279): ACTION_MOVE at 207.000000,
/CustomActivityView(  279): ACTION_MOVE at 214.000000,
/CustomActivityView(  279): ACTION_MOVE at 221.000000,

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#ffdddddd"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ScrollView android:id="@+id/ScrollView" android:layout_width="wrap_content" android:layout_height="wrap_content">
        <HorizontalScrollView android:id="@+id/HorizontalScrollView" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <com.example.eventconsumption.CustomActivityView
            android:background="#ffaaaaff"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/CustomActivityView"
            />
        </HorizontalScrollView>
    </ScrollView>
</LinearLayout>

The view:

package com.example.eventconsumption;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;

public class CustomActivityView extends View {
    private static final String TAG = "CustomActivityView";
    private int mSetViewWidth = -1;
    private int mSetViewHeight = -1;
    private int mScreenWidth;
    private int mScreenHeight;

    public CustomActivityView(Context context) {
        super(context);
        init(context);
    }

    public CustomActivityView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public CustomActivityView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        mScreenWidth = display.getWidth();
        mScreenHeight = display.getHeight();

        setWidthHeight(mScreenWidth / 2, mScreenHeight * 2);
        //setWidthHeight(mScreenWidth * 2, mScreenHeight / 2);
    }

    private void setWidthHeight(int w, int h) {
        mSetViewWidth = w;
        mSetViewHeight = h;
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (mSetViewWidth != -1 && mSetViewHeight != -1) {
            setMeasuredDimension(mSetViewWidth, mSetViewHeight);
        } else {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.i(TAG, String.format("ACTION_DOWN at %f, %f", event.getX(), event.getY()));
            return true;
        case MotionEvent.ACTION_MOVE:
            Log.i(TAG, String.format("ACTION_MOVE at %f, %f", event.getX(), event.getY()));
            break;
        case MotionEvent.ACTION_UP:
            Log.i(TAG, String.format("ACTION_UP at %f, %f", event.getX(), event.getY()));
            return true;
        }

        return super.onTouchEvent(event);
    }
}

The activity:

package com.example.eventconsumption;

import android.app.Activity;
import android.os.Bundle;

public class EventConsumptionTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:52:05+00:00Added an answer on May 17, 2026 at 10:52 pm

    Ok so my workaround is to use an OnTouchListener if the android version is above eclair and use the old code otherwise.
    When registering

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) {
        mUseOnTouchListener = true;
        mHorizontalScrollView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // ACTION_UP check here etc...
    

    The old code

    case MotionEvent.ACTION_UP:
        if (!mUseOnTouchListener) {
    

    and so on…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom View that is nested inside ScrollView and HorizontalScrollView like this:
I have a custom view which has a piano keyboard drawn inside of it.
I have a custom view, that has page and block. But the problem when
I have a custom view with several NSTextField controls for which I want to
I have created one custom view that contains the horizontalscrollview. Now when i changes
I have created one custom view that contains the horizontalscrollview. Now when i changes
I have a custom view with some drawing on it. I want to resize
I have a custom view controller that has a view on the bottom half.
I have a custom Scrollview, HorizontalScrollview, and inside is a dynamic table. Each row
I have a custom view in which i want to drawText with these parameters.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.