In android studio I know that, for example if I will create a folder with name layout-sw600dp, the layout files inside that folder will be used for screens with minimum of 600dp width. I want to know is there a way to name a folder, which will be used for screens with height bigger than width? And if there is no way, how to create behavior like that(i.e. separate layouts for screens with height bigger than width and with width bigger than height)?
You can measure device's height and width with this code:
View view = getLayoutInflater().inflate(R.layout.your_activity, null);
//For example, linear layout
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.yourlinearlayout);
linearLayout.measure(0,0);
int width = linearLayout.getMeasuredWidth();
int height = linearLayout.getMeasuredHeight();
if(width > height) {
// your code here
}
You can use the folder name layout-port - indicating that the device is in portrait mode (taller than wide) or layout-land for landscape mode (wider than tall).
See here for more information on the available options.
There are some screen sizes with width longer than height (tablets for example).
you can check the screen aspect in xml using the "-long" "-notlong" suffix in your layout folder.
This is based purely on the aspect ratio of the screen (a "long" screen is wider). This isn't related to the screen orientation.
>long: Long screens, such as WQVGA, WVGA, FWVGA
>notlong: Not long screens, such as QVGA, HVGA, and VGA
https://developer.android.com/guide/topics/resources/providing-resources
My app scales vertically and cuts off right and left edges. How can I achieve the opposite? For example I have 16:9 portrait image. When I launch it on 16:10 screen in portrait orientation, it should fit horizontally and cut upper and lower edges off. Can I achieve that changing Manifest file? Thanks!
I am new to android and I am designing a screen with two buttons(cancel & Next )in android and the button size should be same.It is normally working 3 inches screen in portrait but when i rotate the mobile to Landscape the size is not same as in portrait.I have used android:weight also and i did not find any changes .could some one help me out of this...thanks in advance.
try to set width and height with dp unit but keep it in your mind your button may larger than screen size when run on small screen device.
I have a device on which I set portrait orientation, but it shows the activity in landscape. The device width is bigger than its height, so it seems to be inverted. What can I do to have this device working like the others?
Note that this device has a keyboard; see this image.
How I can i set different views for horizontal and vertical displays when phone is rotated?
You can describe different layouts for portrait and landscape orientation. You should place layout for portrait mode into res/layout-port, and for landscape into res/layout-land
Read more at http://developer.android.com/guide/topics/resources/providing-resources.html, Providing Alternative Resources section
If you are developing the Application for your own then use wrap_content and fill_parent size in height and width. Becouse if you are given any static value then it will effect on the Layout of your phone size. as there are different sizes of phone available for android in the Market.
Thanks.