I've never tried to do an overlay view, but it seems to me to make sense
that once the overlay view is on top that it would capture all events...

If you want it to propogate to the base view I think you are going to have
to handle it in the overlay and then pass it on to the base view somehow.
Not entirely sure how to do that, but that seems the most logical approach
to me.



----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------


On Mon, Jul 12, 2010 at 2:09 PM, Chris <con...@gmail.com> wrote:

> I'm trying to overlay one view on top of another using addContentView.
> The bottom view has an ImageButton on it linked to a ClickListener.
> This all worked fine until I add the overlay view using:
> addContentView(overlayView, new
> LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
> After that, no click events are seen by my base view. I think I'm
> missing something fundamental about event propagation wrt views, but I
> can't figure it out... any thoughts would be appreciated.
>
> Thanks,
> -Chris
>
> Here's the base view:
>
> --------------------------------------------------------------------------------------------------------------
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>  android:id="@+id/cameraView" android:layout_width="fill_parent"
>  android:layout_height="fill_parent" android:gravity="center_vertical|
> center_horizontal">
>  <RelativeLayout android:layout_width="fill_parent"
>    android:layout_height="fill_parent" android:gravity="bottom">
>    <SurfaceView android:id="@+id/camera_surface"
>      android:layout_width="fill_parent"
> android:layout_height="fill_parent" />
>    <LinearLayout android:layout_width="fill_parent"
>      android:layout_height="wrap_content"
> android:layout_gravity="bottom"
>      android:paddingTop="8dip" android:gravity="center_horizontal"
>      android:background="#AA000000">
>      <ImageButton android:id="@+id/shutterButton"
>        android:layout_width="wrap_content"
> android:layout_height="wrap_content"
>        android:src="@android:id/drawable/ic_menu_camera" />
>    </LinearLayout>
>  </RelativeLayout>
> </LinearLayout>
>
> --------------------------------------------------------------------------------------------------------------
>
> And here's the view I'm trying to add on top:
>
> --------------------------------------------------------------------------------------------------------------
> public class OverlayView extends View
> implements View.OnTouchListener, View.OnClickListener,
> ZoomButtonsController.OnZoomListener {
>
>  private final Drawable overlay;
>  private boolean inDrag = false;
>  private final ZoomButtonsController zoomController;
>  private final float zoomIncrement = 0.1f;
>  private final float aspectRatio;
>
>  protected OverlayView(Context context) {
>    super(context);
>
>    setFocusable(true);
>    setFocusableInTouchMode(true);
>    overlay = context.getResources().getDrawable(R.drawable.overlay);
>    aspectRatio = ((float)overlay.getIntrinsicHeight()) /
> ((float)overlay.getIntrinsicWidth());
>    overlay.setBounds(0, 0, 100, (int)(100 * aspectRatio));
>    setOnTouchListener(this);
>    setOnClickListener(this);
>
>    zoomController = new ZoomButtonsController(this);
>    zoomController.setOnZoomListener(this);
>  }
>
>  protected void onDraw(Canvas canvas) {
>    overlay.draw(canvas);
>    super.onDraw(canvas);
>  }
>
>  public boolean onTouch(View v, MotionEvent event) {
>    switch (event.getAction()) {
>    case MotionEvent.ACTION_DOWN:
>      if (overlay.getBounds().contains((int)event.getX(),
> (int)event.getY())) {
>        inDrag = true;
>      } else {
>        zoomController.setVisible(true);
>      }
>      break;
>    case MotionEvent.ACTION_MOVE:
>      if (inDrag) {
>        Rect bounds = new Rect();
>        overlay.copyBounds(bounds);
>        bounds.offsetTo((int)(event.getX() - bounds.width()/2),
>            (int)(event.getY() - bounds.height()/2));
>        overlay.setBounds(bounds);
>        invalidate();
>      }
>      break;
>    case MotionEvent.ACTION_UP:
>      if (inDrag)
>        inDrag = false;
>      break;
>    default:
>      break;
>    }
>    if (zoomController.isVisible())
>      zoomController.onTouch(v, event);
>
>    return false;
>  }
>
>  public void onClick(View v) {
>  }
>
>  public void onVisibilityChanged(boolean visible) {
>    setOnTouchListener(this);
>  }
>
>  public void onZoom(boolean zoomIn) {
>    Rect bounds = new Rect();
>    overlay.copyBounds(bounds);
>    if (zoomIn) {
>      float width = bounds.width() * (1.0f + zoomIncrement);
>      float height = width * aspectRatio;
>      bounds.set(bounds.left, bounds.top, bounds.left + (int)width,
> bounds.top + (int)height);
>    }
>    else {
>      float width = bounds.width() * (1.0f - zoomIncrement);
>      float height = width * aspectRatio;
>      bounds.set(bounds.left, bounds.top, bounds.left + (int)width,
> bounds.top + (int)height);
>    }
>    overlay.setBounds(bounds);
>    invalidate();
>  }
>
>  protected void onDetachedFromWindow() {
>    zoomController.setVisible(false);
>    super.onDetachedFromWindow();
>  }
>
> }
>
> --------------------------------------------------------------------------------------------------------------
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to