Reputation: 158
Here i develop one android application for both orientation Portrait and Landscape. So i create two layout folder for Landscape and Portrait and create two layout.xml
files one for Portrait and second one is for landscape. In portrait layout.xml
file has one ImageView and In Landscape layout.xml
file has two ImageView. In AndroidManifest.xml
, i set parameter android:configChanges="keyboard|orientation"
in <activity>
entry to stop recreating activity on orientation changes. and In my Activity i override onConfigurationChanges()
as below
public void onConfigurationChanged(Configuration newConfig)
{
try
{
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Toast.makeText(myContext, " Config Changed ", 1000).show();
setContentView(R.layout.double_pageread_layout);
setLayout(); // Initialize Controls (Buttons, ImageView,etc..)
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
But the Problem is that when i run my application. i can see it is perfect But When i change orientation it does not display anything.
Please Help me.
Thanks In Advance.
Upvotes: 0
Views: 283
Reputation: 12672
You do not need to manually change the layout by handling configuration changes. Simply place the two different layout.xml
files into the res/layout
and res/layout-port
folders and Android will automatically inflate the proper one on rotate.
Upvotes: 1