2

I'm currently working on writing an Android Things app and installing it on a Raspberry Pi 3. I have it connected to monitor, but I want to be able to hang the monitor in a portrait orientation, rather than landscape. I've tried adding the following line to the AndroidManifest.xml under activity:

android:screenOrientation="portrait"

However, this doesn't seem to affect how the activity is displayed on the screen. Is there a way to change the orientation to portrait in an Android Things project?

Thomas
  • 1,123
  • 3
  • 13
  • 36
  • 3
    Did you check https://stackoverflow.com/questions/41558508/screen-orientation-on-raspberry-pi-3-with-android-things or https://stackoverflow.com/questions/41165198/android-things-with-rasp3-7-inch-touchscreen/41166605#41166605 – Arun Shankar Aug 10 '17 at 04:42

1 Answers1

1

you can do it something like below

After rootView in your java add this line

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
For Ex:

View rootView = inflater.inflate(R.layout.activityxml, container, false); 

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

And also in your manifest change it

 android:configChanges="orientation|keyboardHidden" as 
 android:configChanges="keyboardHidden"

<activity
android:name="com.test.activity"
android:label="@string/app_name" 
android:screenOrientation="portrait"
android:configChanges="keyboardHidden" >
Nguyễn Trung Hiếu
  • 2,004
  • 1
  • 10
  • 22