Rotate View Hierarchy 90 degrees

后端 未结 6 971
予麋鹿
予麋鹿 2020-11-28 03:33

I am working on a subclass of FrameLayout that is supposed to rotate all of its children by 90 degrees. I am doing this to overcome the landscape-only camera limitation pres

6条回答
  •  庸人自扰
    2020-11-28 04:21

    I had the same problem and managed to solve it. Instead of rotating each view or the layout by hand, I used a LayoutAnimationController.

    First, place a file in /res/anim/ called rotation.xml

    
    
    
    

    Then, in your Activity's onCreate, do

      @Override
      public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
    
         setContentView(R.layout.myscreen);
    
         Animation rotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotation);
         LayoutAnimationController animController = new LayoutAnimationController(rotateAnim, 0);
         FrameLayout layout = (FrameLayout)findViewById(R.id.MyScreen_ContentLayout);
         layout.setLayoutAnimation(animController);
     }
    

    If you want to rotate elements that lie above your camera preview view (SurfaceHolder), simply place a FrameLayout above the SurfaceHolder, place all your elements in that FrameLayout and call the Layout "MyScreen_ContentLayout". Done.

    Hope that helped someone out, took me quite a while to get everything together.

提交回复
热议问题