ok.. for anyone else out there.. I have devised (hacked?) a solution
to this... but it's a bit clumsy.

First I created a custom ImageView in which I added an
OnLayoutListener interface...

public class CustomImageView extends ImageView {

        private final Rect bounds = new Rect();

        private OnLayoutListener onLayoutListener;

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

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

        public CustomImageView(Context context) {
                super(context);
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int
right, int bottom) {
                super.onLayout(changed, left, top, right, bottom);

                if(onLayoutListener != null) {

                        if(changed) {
                                bounds.left = left;
                                bounds.top = top;
                                bounds.right = right;
                                bounds.bottom = bottom;
                        }

                        onLayoutListener.onLayout(bounds);
                }

        }

        public final OnLayoutListener getOnLayoutListener() {
                return onLayoutListener;
        }

        public final void setOnLayoutListener(OnLayoutListener
onLayoutListener) {
                this.onLayoutListener = onLayoutListener;
        }

        public static interface OnLayoutListener {
                public void onLayout(Rect bounds);
        }
}

Then in my activity, I get a reference to the SlidingDrawer and the
CustomImageView

final CustomImageView sliderRefresh = (CustomImageView)
findViewById(R.id.slider_refresh);
final SlidingDrawer slider = (SlidingDrawer)
findViewById(R.id.slider);

// Create a rect to contain the coordinates of the image
final Rect imageRect = new Rect();

And add a listener to the image view

                        sliderRefresh.setOnLayoutListener(new 
OnLayoutListener() {
                                @Override
                                public void onLayout(Rect bounds) {
                                        
sliderRefresh.getGlobalVisibleRect(imageRect);
                                }
                        });

Then reset the coordinates when the slider is opened/closed:

                        slider.setOnDrawerOpenListener(new 
OnDrawerOpenListener() {

                                @Override
                                public void onDrawerOpened() {
                                        
sliderRefresh.getGlobalVisibleRect(imageRect);
                                }
                        });

                        slider.setOnDrawerCloseListener(new 
OnDrawerCloseListener() {

                                @Override
                                public void onDrawerClosed() {
                                        
sliderRefresh.getGlobalVisibleRect(imageRect);
                                }
                        });

Finally in the slider touch listener, see if the touch event was
inside the image

                        slider.setOnTouchListener(new OnTouchListener() {

                                @Override
                                public boolean onTouch(View v, MotionEvent 
event) {
                                        if(event.getAction() == 
MotionEvent.ACTION_DOWN) {
                                                
if(imageRect.contains((int)event.getRawX(),
(int)event.getRawY())) {
                                                        // Handle the click here
                                                        return true;
                                                }
                                        }
                                        return false;
                                }
                        });


Let's face it.. it's a hack.. but it works.

On Apr 10, 11:37 pm, Jason <[email protected]> wrote:
> Hi folks,
>
> I have an ImageView contained in a TableLayout within the "handle"
> component of a SlidingDrawer and I'm trying to capture the click event
> on the ImageView but it doesn't seem to be fired.
>
> Obviously the SlidingDrawer is capturing the event to handle it
> according to the rules governing its behavior, but I would have
> expected the event to be populated down to all child views.. which it
> doesn't seem to be.
>
> I have a structure somewhat like this:
>
> <SlidingDrawer
>         xmlns:android="http://schemas.android.com/apk/res/android";
>         android:id="@+id/slider"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:handle="@+id/panelHandle"
>         android:content="@+id/panelContent"
>         android:allowSingleTap="false">
>         <TableLayout
>                 android:layout_width="fill_parent"
>                 android:layout_height="36dp"
>                 android:stretchColumns="1"
>                 android:id="@+id/panelHandle">
>                 <TableRow>
>                         <ImageView
>                                 android:id="@+id/slider_refresh"
>                                 android:layout_width="wrap_content"
>                                 android:layout_height="wrap_content"
>                                 android:src="@drawable/refresh"
>                                 android:paddingRight="8dp"/>
>                 </TableRow>
>         </TableLayout>
>
>         <LinearLayout
>                 android:id="@+id/panelContent"
>                 android:orientation="vertical"
>                 android:layout_width="fill_parent"
>                 android:layout_height="fill_parent">
>                 <ListView
>                         android:id="@+id/section_list"
>                         android:layout_width="fill_parent"
>                         android:layout_height="fill_parent"
>                         android:divider="#CCCCCC"
>                         android:cacheColorHint="#00000000"
>                         android:background="@color/white"
>                         android:dividerHeight="1px" />
>         </LinearLayout>
> </SlidingDrawer>
>
> I'm wanting to capture the "onClick" event on the "slider_refresh"
> view:
>
> View sliderRefresh = findViewById(R.id.slider_refresh);
> sliderRefresh.bringToFront();
> sliderRefresh.setOnClickListener(new OnClickListener() {
>                 @Override
>                 public void onClick(View v) {
>                         LogSystem.getLogger().info("Refresh clicked");
>
>                 }
>
> });
>
> But the event doesn't seem to be populated onto this view.
>
> Anyone got any clue as to how I can capture this event?
>
> Thanks

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

Reply via email to