I have the main Activity which has 4 images on the canvas with the screen Orientation as "portrait". When I traverse to the child Activity which has the screen Orientation as "landscape".
Issue : When I come back from the child Activity to the main Activity the 4 images are relocated to different position. I need to resolve this so that the Activity is fine even for the change in screen orientation.
Thanks in Advance.
Layout
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black">
<activity
android:name=".DragDrop"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".QuizHard"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.QUIZHARD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
you can set the orientation to portrait of main activity and landscape of child activity in android manifest file.
<activity android:name="Main"
android:screenOrientation="portrait"/>
similarly set orientation to landscape for child activity.
You can add statements to your AndroidManifest.xml file to tell it to handle certain screen changes, such as orientation changes. Normally, when the orientation changes, a new layout is loaded and the screen is recreated, by adding this statement to the manifest file, it won't recreate the view. Change the activity declaration of your activities and add this statement.
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The android:configChanges="orientation" will prevent Android from recreating the activity, thus preventing it from reloading the view and changing the image positions. You can also add android:screenOrientation="portrait" right after the configChanges statement if you want Android to lock the orientation to portrait, or landscape, if you want.Hope this helps! Would love to hear back from you with the results.
You can add orientation to activity in manifest like this
<activity android:name="Main" android:screenOrientation="portrait"/>
or you can set layout orientation in java file like this
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Related
Is there a way to 'freeze' the application in either landscape or portrait mode, so turning the device/phone would not turn the app view but it would stay in either landscape or portrait?
Thanks
Yes.
In you manifest file, just add android:screenOrientation="portrait" for all your activities.
Your activity tag for your launcher activity should look like this:
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You will have to do this for all your activities. There is no option available to specify it in the application tag.
I have a big issue for those phones that have not only the softkeyboard that all phones have (on screen)... i'm talking about those phones with external keyboard hardware.
in these moment I've set all activities, forcing one way, portrait. Now here comes the problem when the user flips his external keyboard, the activity changes orientation forcing the app to close.
if someone dosn't know which phones i'm talking about here is an example:
Phone with external keyboard
Piece of my manifest;
<activity
android:name=".Splash"
android:label="#string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
</activity>
How can make the keyboard to ignore orientation?
Try adding this to your activity manifest.
android:configChanges= "keyboardHidden|orientation"
I have designed an activity that its orientation is landscape. Also I have designed another that its orientation is portrait. When I run in my phone, there are some problems comes to when the landscape activity back to the portrait activity.
Some of the layout disappear, such as below
original:
after
can anyone help me to solve this problem?Thank you so much!
<activity android:name="TestingActivity" android:screenOrientation="portrait" android:configChanges="orientation" > </activity>
<activity android:name="Main">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<activity android:name=".TestingActivity2" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:screenOrientation="landscape" />
Your problem is in layout-portrait xml file. You can fix it by redesigning it. Please post your code.
I am finding that in my Android application, the name of the application is displaying on the top of every screen, consuming a line of valuable screen real estate.
I am using LinearLayouts
How can I get this not to display?
You can set it in the Activity/Application tags in the manifest XML:
android:theme="#android:style/Theme.NoTitleBar"
See more here (Styles and Themes).
Or write in onCreate yours Activity before setContentView():
requestWindowFeature(Window.FEATURE_NO_TITLE);
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<activity
android:name=".A"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
you can add this line android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" to the manifest and make your application fullscreen and without title bar
and if you want to remove only the title bar and don't want to make the application full screen then you can use Theme.NoTitleBar
Change your activities' theme like that
<activity android:name=".Activity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:theme="#style/AppTheme"
Above change in Manifest file didn't work for me.
requestWindowFeature(Window.FEATURE_NO_TITLE)
For this to work in your project you have to make one more change. Make your acivity extends Activity instead of AppCompactActivity which comes by default.
Thank You.
I have meet a problem, there is a tabhost in my app.which have 4 tabs,each tab have more than one activiy.I just want to fix some of activities in portrait mode while other's can change orientation mode,any suggestions?
<activity android:name=".MyTabHost"
android:windowSoftInputMode="adjustPan|stateVisible"
android:configChanges="keyboardHidden|orientation"
></activity>
<!-- android:screenOrientation="portrait" -->
<activity android:name=".Products_Images"
android:configChanges="keyboardHidden|orientation"
></activity>
<activity android:name=".Products_Upload"
android:screenOrientation="portrait"></activity>
<activity android:name=".Products_Description"
android:screenOrientation="portrait"></activity>
in products_images.java,i just want to show larger image while orientation changed,however in products_upload.java and products_description.java,i just want to fix orientation in portrait mode, all three class just in one tab.but it doesnt work!!
use this in activity tag in manifest file:
android:screenOrientation="portrait"