I want to show two extra textfields when my application is shown in landscape. I know I can do this by copying my original layout to folder layout-land and just add 2 fields, but that way I need to maintain 2 versions of my layout file, the original one and the one copied to folder layout-land. What I actually want is just add two textfields without the need for maintaining 2 copies of a layout file. Can you do that ?
thanks, Steef
The idea which I've thought is may or may not be correct. My idea is to check the device orientation in class file and when the layout is landscape, just manipulate your layout or simply mean just add two text field at that time. Hopefully! it will work.
Happy Coding!!!
Im beginner but i might have some idea. If you dont want to have 2 layouts file, there is second options- make styles.xml for portrait and land and you can write style which set visibility. Try something like that.
Related
I have an activity which contain 3 fragments. 2 of them have data in a listview therefore when user rotate the screen everything is ok. but on my third fragment which contain buttons, when the user rotate the screen to landscape orientation,everything goes astray!
my third fragment in protrait orientation
my third fragment in landscape!
I have even tried to use scrollview but it's not working because when in landscape i don't want that big space at the middle. i wan't 3 x 2 buttons arrangment(i have 6 buttons.) when in landscape. and i think i can only achieve that by using 2 xml layouts for my fragment.
Question is how can i do that?
Make another layout folder layout-land under res and create landscape orientation layout file under this folder
After great help from sai Phani(see his comments above). i finally achieved my objective which was to create a landscape layout for my fragment by doing the following.
Create a folder under src\main\res and call it layout-land
copy your fragment layout xml (e.g peoplefragment.xml) which is in src\main\res\layout and paste it into src\main\res\layout-land folder. Don't change the file name!
Once you have pasted it, you can change the views alignment the way you would like them t appear on landscape. for my sutuation, i wanted them to appear like this in landscape
You may design your layouts that looks good for both portrait and landscape but you may customize for both orientation.
Look at SO link on the same issue # Android: alternate layout xml for landscape mode. The idea is simply to create folder names the correct way specified in Google documentation.
A good Google webpage is # Supporting Multiple Screens, search for "Using configuration qualifiers". There is a table stating Orientation and the folder names to use.
I need to make almost the same xml layout, except for some buttons, when i copy all the elements, the textviews, imageviews, buttons - all get same id! So i have to manually change the ids, i can copy 1 by 1 and each id name will be preserved.
But i am a programmer! Is there way to automate it, do it faster, more efficient?
example here , i copied half of the elements and they changed their ids automatically:
the answer is pretty simple actually: just switch to text tab in android studio, copy the actual xml code and paste it wherever you need, this way when you switch back to "design" mode - you will see all the ids in place!
I want the same application to be delivered 2 different set of layouts. Ie the functionality is same but the graphics will be different for two different versions of the app. So i want to keep the same code and based of some variables want to decide which layout to be set for each activity. SO for each activity i will define two different layout.
This is my requirement. What is the best way to implement this. I can have an if else in each activity and define which layout to be set. Is that the right and best way. Please give your options on this
Take a look at this answer. It's about accessing a resource file from identifier, ie file name. You can do this with any type of resource (I think).
How to use getResource.getIdentifier() to get Layout?
Basically, you can do an if-else statement and assign the id of the layout you wish to use to a variable then load the layout using the identifier.
Actually there are many ways for ex you can change your layout based upon the orientation i.e landscape or portrait or you can change your layouts using languages for ex- you can create various folders for different languages.
Please explain your requirement briefly and if possible post some code also.
You can follow below links also.
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screendensities.html
Language Specific layout for android
http://www.c-sharpcorner.com/UploadFile/0e8478/supporting-different-languages-layouts-in-an-android-appli/
I developed a application. In that i get GUI perfect in portrait, but when i tern my emulator(pressing Ctrl+F11) some text and buttons will be miss ordered. i searched so many sites but i am not get the solution.
Please any one give a solution.
Thank You.
For solving these problem you should make two layout for different different
1-: create a new folder in side the resource is layout-land then put your layout for landscape in this folder.
2-: another one is use for portrait mode its put in layout folder.
you can create your application to support landscape mode by creating different layouts.
simply you can create a folder in your res folder like this -> /res/layout-land and copy your layouts and make necessary changes(for landscape) to it.
please read the documentation for further details
tutorial
can anybody tell how to load different xml file whenever user changes device orientation in android?
For example, I am using a profile screen in my application. In portrait mode, user gives 'user name' value, after that I change orientation to landscape, now I have to load different xml, so that user gives value in landsacpe mode.
Is it possible?
Thanks
Editor's Note: English doesn't seem to be his first language.
create two types of layout directories to handle orientation . layout-land layout-port
put the xml with the same name in both the directory. if i have main.xml file then i have to put it in both directory.
Thanks
Provide a different layout in layout-land\
See http://developer.android.com/guide/topics/resources/providing-resources.html
yes it is possible. If the user has changed the orientation then you can set different XML on setContentView(R.id.xml)
You need to implement OnConfigChange Method so when ever orientation change at that time this method will call autmatically and setContentView(R..id.nameofxml) from layout-land folder.