How to Landscape Activity in the TabHost? - android

My question is how to landscape Activity or TableLayout in the TabHost Layout?
I mean How to do something like this?
My Situation is the same this question
Android: Landscape Child Activity in a Portrait Tab Activity
Thanks,,,

As per my knowledge, all the layouts can automatically converts themselves in changed orientation mode. Please use below code to handle orientation mode.
Apply below code in menifest files for each activity for each tab.
android:configChanges="orientation|keyboardHidden"
Then apply below code to each code of each activity.
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
//Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_SHORT).show();
{
}
else
{
}
}

Related

Make Multiple Activites Landscape If App started as Landscape

What is Problem?
if app started as portrait then make activity as portrait , otherwise landscape , but don't detect sensor based or used based rotation otherwise.
My Solution:
Make variable isPortrait in application class and detect orientation in onCreate of Application class then use this variable in all activites to detect what orientation to use.
Problem in My Solution:
No Idea how can I change different configuration layouts and map them accordingly in this scenario , what if user change it orientation to landscape after app started in portrait ? is there any ActivityInfo flag to achieve this behaviour.
use this in your activity tag in manifest
android:configChanges="orientation"
android:screenOrientation="portrait"
In Mainfest within the atvitity tag add below code
android:configChanges="orientation|screenSize"
and in ur activity override onConfiguration method like below
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
log.e("onConfigurationChanged", "screen orientation change");
}

Tab Widget Issue when use android:configChanges="orientation|keyboardHidden" in Grid View but working for other Tab

I am stuck with my issue.Thing is that its a custom Tab Widget.In that have multiple
tab like Home - News - Abc - PQR .
The Activity should be for both orientation like portrait and landscape. so for that each tab have two xml for portrait which is store at layout-port/file.xml and landscape which store at layout-land/file.xml
For manage orientation portrait to landscape i have added android:configChanges="orientation|keyboardHidden" rule tag in each activity.
TAB_SAMPLE.java Tab file.
TAB_GROUP_ACTIVITY each Tab Group activity File
file.java Task file
After all this stuff i get issue here :
If i addandroid:configChanges="orientation|keyboardHidden"rule tag in tab_sample activity then its working perfect. like manage different view. port to land and land to port but its not working in Home.java.
Now if i remove android:configChanges="orientation|keyboardHidden" rule tag in tab_sample activity then its working for Home activity not for News.java
Mean when i change the orientation its keeping same xml form port not use from layout-land.in the sense its call OnCreate() again.
So as i found may be issue is in Tab Widget.
Update
Now after tracing my code i get that main issue is in grid view activity because its only activity which is not working.
Issue is between Tab host v/s Grid View. I don't know why its not taking layout-land xml file. i found this as same issue but no replay on that question also
see in Detail manifestfile.xml
I want to maintain both portrait and landscape in all activity.
Both XML File
Please help me how to solve this.
Oooohhh Finally i got the solution for above issue. It's was very difficult.
For maintain the state of orientation Landscape to portrait and vice-versa we generally adding android:configChanges="keyboardHidden|orientation" property tag under activity.
But here may be issue is Tab_Group_ Activity due to that i am not able to maintain state in GridView. Grid_File.java is Only single java file which was not handling the orientation rest of all other working perfectly.
Now if i remove android:configChanges="keyboardHidden|orientation" from TAB_SAMPLE.java then Its handling only Grid_File.java not others.
mean that was keeping same Layout XML in landscape also where i have two separate XML File.
Here is my solution:
I have add android:configChanges="keyboardHidden|orientation" in TAB_SAMPLE.java as well as
implement onConfigurationChanged(Configuration newConfig) and set Number of column of grid. like gridView.setNumColumns(6);
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// gridView.setSelection(index);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// Log.e("On Config Change", "LANDSCAPE");
gridView.setNumColumns(6);
} else
{
// Log.e("On Config Change", "PORTRAIT");
gridView.setNumColumns(4);
}
}
Generally we are adding either android:configChanges="keyboardHidden|orientation" tag under activity or implementing onConfigurationChanged(Configuration newConfig) but here i have written both.

Show different layout for both orientations

In my android application i designed two different layouts with same file name say my_profile.xml, and stored in two different directories i.e, 1) res/layout, 2) res/layout-land. Now the problem is if i start activity in Portrait mode it loads Portrait mode layout but after changing orientation it doesn't change layout, But if i start activity in Landscape mode it loads layout of landscape i.e, perfect. Problem is only when i change orientation, it doesn't handle it automatically. Can any one tell me, what can be the problem?
Check for the following :
1) In manifest file check for the below line in your activity
android:configChanges="orientation|keyboardHidden|screenSize"
2) Override the below function
#Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.d(tag,"onconfig");
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// do something
Log.d(tag,"land");
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
// do something
}
}
-Preeya
In your manifest.xml make the changes like this,,,,,
<activity android:name=".myActivity" android:windowSoftInputMode="adjustPan" android:configChanges="keyboardHidden"></activity>
dont use configuartionChanges="orientation"
Thats it...
Check your manifest file. If you have the following in your activity then REMOVE IT:
android:configChanges="keyboard|orientation|screenSize"
orientation causes the the activity to resort to the same layout rather than creating a new one.

how to Manage Child activity within Tab Acivity when orientation changes?

I'm using tab widget.
When my child activity is running and I change the orientation,child activity destroy.
As a solution of this problem,I added
android:configChanges="orientation|keyboardHidden in all activity tags in my manifest.xml file.
I found that my app doesn't take xml file from layout_land folder.
Can anyone give me solution for this query?
Thanks in advance.
I found that using onConfigurationChanged method i can know the orientation and i have to set landscape file in layout folder instead of layout_land folder.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
setContentView(R.layout.login_landscape);
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.login);
}
}
This happens because your Activity is not destroyed since you have put android:configChanges="orientation|keyboardHidden" in manifest so the setContentView is not called when orientation changes and therefore it doesn't pick the layout from the layout_land
Update : And this is not a problem with your Tab-Activity try it in normal activity it will not pick the correct layout or in general speaking no layout is picked your portrait layout is only rotated to be displayed in landscape

Android start layout with current orientation, after that disable rotation

I want to make possible to use an activity in landscape / portrait. The activity starts with the layout for the current orientation (that means before starting the activity). After that it has to stick to it, and not react to orientation change.
I tried putting
android:configChanges="orientation"
in the manifest of the activity, and overriding
#Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
}
to do nothing (tried commenting the super call too, but this lead to exception)
but this has not the effect disabling the rotation change - the change is processed and the layout reconstructed, it just doesn't use the correct one.
And I can't use
android:screenOrientation
Because it seems I have to specify only one mode for always, and that's not what I need either.
And anyways, if I specify something there, the activity gets reconstructed when rotating.
Tried with
android:screenOrientation="nosensor"
that doesn't do anything
Here there's a lock of current orientation with code
http://www.samcoles.co.uk/mobile/android-lock-and-unlock-screen-orientation/
But it achieves the same effect as specifying orientation in XML (keeps layout but reconstructs the activity). It's a bit nearer to what I want (keeps orientation from start), but reconstructs the activity and I don't want it to react at all.
android:configChanges="orientation" doesn't work on the emulator at all, but it works fine on devices.
Try
#Override
public void onConfigurationChanged(Configuration newConfig) {
newConfig.orientation = getResources().getConfiguration().orientation;
super.onConfigurationChanged(newConfig);
}
Add this to onCreate
if (this.getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);}
else {setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}

Categories

Resources