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?
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.