Tuesday, July 3, 2012

Re: [android-developers] Re: Getting action bar height while minSdkVersion is 7


OK, this is part of my code, very simple:

    public boolean onTouchEvent(MotionEvent event) {

    int count = event.getPointerCount();

...

        

    int action = event.getAction();

        int x = (int) event.getX();

        int y = (int) event.getY() - absize;

...

    

    return true;

    }


The absize is the current Action Bar height I am using. If without it, event.getY() will works fine in Android 1/2 devices, but on my HTC Jetstream (Honeycomb) and Galaxy Note, the Y value is offset by 56 pixels (which is my current absize). In both cases, I tested them with finger and stylus.


Ideally it should be like what you say, event.getY() just works, but it does not. My minimum SDK level is 7 as I intend to support older devices but allows for Action Bar on Android 3/4 devices. I think this might be the issue (ie, getY() will works fine if my minimum Android version supports Action Bar by default).


在 2012年7月4日星期三UTC+8上午9时30分57秒,Dianne Hackborn写道:
What you are claiming is happening is...  well, you probably need to explain more.

If you have an action bar, then by default your content is placed below it, and the coordinate space of events received by the view will be relative to where it is placed.  This is true with all views in the hierarchy.  If it wasn't, all of your presses on UI elements in a window that has an action bar would be off.

I can't understand how you are doing things such that you have to subtract an offset.  Your content is below the action bar...  that's where it is, there is no offset to subtract.

If you *want* your content to go behind the action bar, you can request the feature that the action bar be shown as an overlay on top of it: http://developer.android.com/reference/android/view/Window.html#FEATURE_ACTION_BAR_OVERLAY

Using this does mean that the top of your content will be covered by the action bar when the action bar is not hidden.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment