Android cannot find declaration of RelativeLayout - android

I am creating different layouts to support different screen sizes.So I created folders like layout-small,layout-large and so on.But I am stuck with the error cannot find the declaration of element RelativeLayout. How do I solve this?

#jobin , android till now does not allow to create seperate layout folders/packages , so please create all your layouts in the layout folder only, u can use prefix or postfix tags to differentiate between layouts.
for ex
activity_main_small ,
activity_main_big ,
activity_main_verybig
but do remember to keep all layout Xmls under the single layout folder provided .

Related

Add 2 buttons in android layout-land

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.

android: design code to dynamicaly select layouts

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/

How to set up a layout using code and not XML

I'm learning to develop android apps and in the process I realized that there two ways to get a job done. Using xml or normal code. Suppose I want to change the position of a button, I'll be doing it in xml using align left/align centre etc., This will be done in the XML file. If I want to achieve the same through code, where should I place the code ? Inside which class ?
There are two aspects to your question that I understand.
1. Creating a whole layout file dynamically (without XML).
2. Creating a layout through XML and changing the components positions and properties dynamically through your activity file.
Now, it's upto the developer what he wishes to choose.
To help you further, please view this video link posted by the Android team.
It's all about layouts and includes how to layout apps using Java, not XML. However, you are warned that the android team wants you to use XML.
The code will be placed in the same class as the class where you reference your xml code. Do a read up in your android docs for insight.

Which XML files is to be used for different screens

I am working on android app and I have created different screens for different layouts.There are 3 types of Android XML files, Android Layout XML and Android values XML.Which one is to be select. Please suggest
Use only Layout XML for layout and for landscape create another folder layout-land inside res folder and create layout of same name with different design suitable in landscape mode. And use different layouts with same name and same Id of all the child view.then android automatically pick when orientation changes
use this for reference
http://developer.android.com/guide/practices/screens_support.html#range

how to add number of button in run time in android

I am beginner in android development and my problem is that ı want to add some buttons in runtime. I mean, number of button will be change according to flow of program so i need to create different number of buttons at different situations. In code section i can handle it by using array but what about layout file? how can ı set the layout file according to flow of program. I hope ı could explain my problem. Thank you very much.
The xml files in res/layout are static descriptions of layouts. You can create different ones to be used in different contexts (different activities, dialogs, etc). You can actually even replace one layout with another one in the same activity. What you cannot do is to modify the xml files during runtime.
If your UI depends on runtime variables, then you will have to act accordingly. If it's just the number of buttons that will change, you can either
Add new buttons using addView(button);
Add a ListView to your xml file and use an ArrayList and an ArrayAdapter to determine how many buttons you will need.

Categories

Resources