0

I've develop Unity3d's android plugin to play video so I use TextureView to render a video.

Everything work well but when I want to set my TextureView object's rotation to 90 it will be invisible while another value such as 30, 60 even 89.92 work.

I don't know why it occurs

And this is my code while creating a TextureView object.

    Activity a = UnityPlayer.currentActivity;
    mediaPlayerContainer = new TextureView(a);
    RelativeLayout.LayoutParams l;
    l = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    l.addRule(RelativeLayout.CENTER_IN_PARENT, -1);
    mediaPlayerContainer.setLayoutParams(l);
    mediaPlayerContainer.setRotation(89.92f);
    mediaPlayerContainer.setFocusable( true );
    mediaPlayerContainer.setFocusableInTouchMode( true );
    mediaPlayerContainer.setVisibility(View.GONE);
    mediaPlayerContainer.setSurfaceTextureListener(this);
    layout.addView(mediaPlayerContainer, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

1 Answers1

0

Because the pivot point is not in the center of the TextureView but the left top.

You should translate a little at first, do the rotation then translate back.

for example:

mView.translate(-mView.getWidth()/2, -mView.getHeight()/2);
mView.setRotation(90);
mView.translate(mView.getWidth()/2, mView.getHeight()/2);
dragonfly
  • 1,151
  • 14
  • 35