1

I'm having a tough time forcing my app to use portrait mode on Google TV. I know this is technically unsupported but I feel like I should be able to do this manually somehow, especially seeing as some apps on Google Play successfully force this behavior system wide (like: https://play.google.com/store/apps/details?id=com.coinsoft.android.orientcontrol and https://play.google.com/store/apps/details?id=nl.fameit.rotate&hl=en).

In my activity I am doing:

public void onStart() {
    View root = findViewById(android.R.id.content);     
    Animator anim = AnimatorInflater.loadAnimator(this, R.anim.rotate_90);                  
    anim.setTarget(root);
    anim.start();
}

My rotate_90.xml:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="0"
    android:propertyName="rotation"
    android:repeatCount="0"
    android:valueTo="90"
    android:valueType="floatType" />

This seems to work, but of course doesn't do exactly what I want. The view is rotated, but all the items on the far left are now off screen. Is there a way to dynamically re-size the root layout to fit the screen in portrait mode?

powerj1984
  • 2,216
  • 1
  • 22
  • 34

2 Answers2

2

Is there a reason that you are attempting to force your app to run in an orientation that isn't supported by the device? If you are writing your app from scratch anyways (which it sounds like), why not support the proper screen orientation?

David C. Sainte-Claire
  • 2,461
  • 1
  • 15
  • 12
  • I realize I'm going outside of what the creators of GTV intended (family entertainment). I'm basically creating a kiosk style application. My client would like this particular kiosk to be in portrait orientation. It might be worth switching to Android on Raspberri Pi or even a minimal Linux install and writing the application as a web site or something, but I'd like to use GTV (the excellent Anymote protocol allows me to easily do some neat interactive things cheaply). – powerj1984 Nov 01 '12 at 23:05
  • hey, @powerj1984. I am in a same situation and want to create a portrait mode app for Android TV. Would you like to share your approach? – aareeph Aug 05 '19 at 12:28
  • The answer I wrote and accepted worked for me (https://stackoverflow.com/a/13166430/104527) - did you run into issues doing that? – powerj1984 Aug 05 '19 at 14:21
1

Of course right after posting I came up with something that seems to work:

    View root = findViewById(android.R.id.content);


    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;

    root.getLayoutParams().height = width;
    root.getLayoutParams().width = height;
    root.requestLayout();

    root.setPivotX(height);
    root.setPivotY(height);

    Animator anim = AnimatorInflater.loadAnimator(this, R.anim.rotate_90);      
    anim.setTarget(root);
    anim.start();

Any better answers would be appreciated, but I don't see any downsides to this off the top of my head.

powerj1984
  • 2,216
  • 1
  • 22
  • 34