1

I have an AppCompatTextView able to scale, rotate and move on top of a video, using the gesture recognizer. It should work almost like when inserting a text over IG stories. The problem arises when I rotate the AppCompatTextView that gets cut meanwhile I am rotating it with my fingers instead when I release my fingers the text appears well. The Video is reproduced over a SurfaceView with the help of MediaPlayer. I was reading that SurfaceView hides other components on the screen, and I tried to call setZOrderMediaOverlay() on the surface but I didn't have any results.

This is how I rotate my view, it works well when I don't have the SurfaceView below it:

  @Override
        public boolean onRotate(RotateGestureDetector detector) {
            mRotationDegree -= detector.getRotationDegreesDelta();
            DisplayMetrics displayMetrics = new DisplayMetrics();
            ((Activity) getContext()).getWindowManager()
                    .getDefaultDisplay()
                    .getMetrics(displayMetrics);
            int height = displayMetrics.heightPixels;
            int width = displayMetrics.widthPixels;
            getLocationOnScreen(location);
            double width_view = getMeasuredWidth() * getScaleX();
            double height_view = getMeasuredHeight() * getScaleY();
            double angle = mRotationDegree;
            angle %= 360;
            if(angle > 0){
                angle -= 360;
            }
            angle = Math.abs(angle);

            if((angle >= 0 && angle <= 90) ) {
                location[1] = location[1] - (int)(Math.sin(Math.toRadians(angle))*width_view);
            }else if((angle >= 90 && angle <= 180) ){
                angle = 90 - angle % 90;
                location[0] = location[0] - (int)(Math.cos(Math.toRadians(angle))*width_view);
                location[1] = location[1] - (int)(Math.sin(Math.toRadians(angle))*width_view) - (int)(Math.cos(Math.toRadians(angle))*height_view);
            }else if((angle >= 180 && angle <= 270) ){
                angle = angle % 90;
                location[1] = location[1] - (int)(Math.cos(Math.toRadians(angle))*height_view);
                location[0] = location[0] - (int)(Math.sin(Math.toRadians(angle))*height_view) - (int)(Math.cos(Math.toRadians(angle))*width_view);
            }else{
                angle = 90 - (angle % 90);
                location[0] = location[0] - (int)(Math.sin(Math.toRadians(angle))*height_view);
            }


            return true;
        }
    }

This is the main part of the Layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:id="@+id/frameContainer"
    tools:context=".VideoPreviewActivity"
    >

    <SurfaceView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/surfaceView1"
        android:layout_gravity="center"
        />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/textContainer"/>
</FrameLayout>

Example of the problem

David Vittori
  • 1,146
  • 1
  • 13
  • 30

0 Answers0