Вращающийся вид на поверхность - PullRequest
1 голос
/ 10 января 2020

У меня есть AppCompatTextView , способный масштабироваться, вращать и перемещаться поверх видео, используя распознаватель жестов. Это должно работать почти так же, как при вставке текста в истории IG. Проблема возникает, когда я поворачиваю AppCompatTextView , который обрезается, в то время как я поворачиваю его пальцами, а когда я отпускаю пальцы, текст выглядит хорошо. Видео воспроизводится через SurfaceView с помощью MediaPlayer . Я читал, что SurfaceView скрывает другие компоненты на экране , и я пытался вызвать setZOrderMediaOverlay () на поверхности, но у меня не было никаких результатов.

Вот как я поворачиваю свой вид, он хорошо работает, когда у меня нет SurfaceView под ним:

  @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;
        }
    }

Это основная часть 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

...