Android: alternate layout xml for landscape mode
By default, the layouts in /res/layout
are applied to both portrait and landscape.
If you have for example
/res/layout/main.xml
you can add a new folder /res/layout-land
, copy main.xml
into it and make the needed adjustments.
See also http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts and http://www.devx.com/wireless/Article/40792/1954 for some more options.
how to add altarnative layout for landscape in android
Use folder like below in your res
folder
- layout-small-land
- layout-normal-land
- layout-large-land
- layout-xlarge-land
How do I specify different layouts for portrait and landscape orientations?
Create a layout-land
directory and put the landscape version of your layout XML file in that directory.
Different screen sizes? (landscape)
So, your current structure is:
layout
layout-large
layout-normal
layout-small
layout-large
To specifiy layouts for landscape mode for each of these sizes create the following folders and put your size-specific layouts in there:
layout-land
layout-large-land
layout-normal-land
layout-small-land
layout-large-land
Android annotations: Different layout for portrait and landscape
Add the following code in your java file
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
setContentView(R.layout.activity_main_h);
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(this);
}
else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
setContentView(R.layout.activity_main_v);
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(this);
}
}
Also, add the following to your activity in the Manifest:android:configChanges="keyboardHidden|orientation|screenSize"
Android Studio: multiple layouts, specifically landscape tablet
Click Create Other.. Select Orientation from Available Qualifiers box. Click >> button. In Screen Orientation select Landscape. In directory name paste this : layout-sw600dp-land
A new folder will be created with the same name having activity_main.xml in sw600dp(tablet 7" size) in landscape mode. Configure as per your requirement.
Different design for landscape and portrait orientation android
Yes ofcourse.
You will have to create two versions of xml files and put in layout-port and layout-land folder inside res folder.
eg :
res/layout [Portrait Mode; default]
main.xml
res/layout-land [Landscape Mode]
main.xml
You can refer further more on the same at http://developer.android.com/training/basics/supporting-devices/screens.html
Android XML layout declaration (portrait, landscape modes)
IF you have separate layout files (i.e.: for different orientations), they can be completely different.
however it depends how you would like to use them in your code.
Update:
To check orientation in code use:
getResources().getConfiguration().orientation
It is either ORIENTATION_LANDSCAPE
or ORIENTATION_PORTRAIT
.
http://developer.android.com/reference/android/content/res/Configuration.html#orientation
Related Topics
Difference Between "@Id/" and "@+Id/" in Android
Android: Check Whether the Phone Is Dual Sim
How to Define Callbacks in Android
How to Create Our Own Listener Interface in Android
Programmatically Register a Broadcast Receiver
Notification Not Showing in Oreo
Linear Layout and Weight in Android
Android Check Internet Connection
Communicating Between a Fragment and an Activity - Best Practices
Viewpager and Fragments - What's the Right Way to Store Fragment'S State
Android: Listview Elements With Multiple Clickable Buttons
How to Manually Include External Aar Package Using Gradle For Android
How to Display a Toast from a Background Thread on Android
Integrating the Zxing Library Directly into My Android Application
Filter Logcat to Get Only the Messages from My Application in Android
How to Start a Service When .Apk Is Installed For the First Time