Android查找旋转视图超级视图的子视图坐标

时间:2014-06-07 00:33:55

标签: android android-layout rotatetransform

我有一个使用RotateAnimation旋转的相对布局。在布局的一角有一个按钮。旋转视图后,该按钮不再接收onTouch事件。我尝试了一些事情:

    float rotation = 90f;
    Rect closeButtonRect = new Rect();
    //close button reference in layout
    closeButton.getGlobalVisibleRect(closeButtonRect);
    RectF closeButtonRectf = new RectF(closeButtonRect);

    //1. get location of layout rectangle in parent
    Rect rect = new Rect();
    getGlobalVisibleRect(rect);
    RectF rectf = new RectF(rect);

    //2 rotate the rectangle
    Matrix matrix = new Matrix();
    matrix.setRotate(rotation,rectf.centerX(), rectf.centerY());
    RectF destRect = new RectF();
    matrix.mapRect(destRect, closeButtonRectf);
    Log.d(TAG, "dest rect: " + destRect + " contains: " + destRect.contains(motionEvent.getRawX(), motionEvent.getRawY()));

我是否在正确的轨道上?我是否必须从超视图转换所有触摸事件以查看触摸是否在旋转视图的矩形中?

<RelativeLayout
android:layout_width="300"
 android:layout_height="300">

<ImageView
    android:id="@+id/bg_border"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_placement"/>

<ImageView
    android:visibility="gone"
    android:scaleType="centerCrop"
    android:id="@+id/poof_animation"
    android:layout_centerInParent="true"
    android:layout_width="@dimen/poof_view_size"
    android:layout_height="@dimen/poof_view_size"
    android:background="@drawable/poof_delete"/>

<ImageButton
    android:id="@+id/closeButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
    android:src="@drawable/btn_close_tool"/>

</RelativeLayout>

0 个答案:

没有答案