How to change the layout of an app to LandScape and how to make the layout of an app adaptable to mobile and tablets

StackOverflow https://stackoverflow.com/questions/18914699

I'm new to android and I would like my app that when it is opened, it's orientation or layout is changed to landscape, just like in some games I downloaded from the Play Store. I also want to know to how to make my app have the ability to adapt its layout whether it is installed in a mobile phone (around 4 inches in screen size) and a tablet (like samsung galaxy tab 2 7.0). I just recently installed an app I created in our tablet and its layout changed, 2 buttons are on top of each other and a textview is covering another button because I found out that the layout I created is for a mobile phone.

I hope someone can give me a detailed explanation and example on this.

Many thanks in Advance.

有帮助吗?

解决方案

Basically what you can do is avoid the use of static dimensions. This is the main reason of your problem. Make the use of wrap_content or match_parent and if you are using LinearLayout then adjust components through weights and if you are using RelativeLayout then adjust the components with respect to each other and for all these you will have to go through layouts throughly and learn the use of dimen.xml.

Go through this...

其他提示

First of all I suggest that you should read Support For Multiple Screen.And forcing your app to open in landscape or portrait mode you set it in your AndroidMenifest.xml file like below.

  <activity android:name=".YourActivity" android:screenOrientation="portrait" ></activity>

Hope this will be helpful to you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top