I am developing a single application for both tablets and for handsets..My app is currently running fine on handsets(as according to layouts and all)..but i have no idea for how to distinguish it for handsets/tablets. I have seen some of the answers in Stackoverflow.com too, in which some people answered that use different layout-large,layout-xlarge.
but if the layout differs and we follow the above scenario,then in programming,it is written setcontentView(R.layout.---).
So we have to mention here also that setContentView(R.layout-large.---)..I am so confused with this..Can anyone suggest me something...
you only need to name the folder differently those contain same nameLayout.xml
like so
--layout
-- myLayout.xml
--layout-large
-- myLayout.xml
--layout-xlarge
-- myLayout.xml
on code, you only need to use
secContentView(R.layout.myLayout);
android will find the right one for you.
The android os will select the appropriate folder based on the device dimensions and other properties.
So you can keep the resource name same in all the folders and android will pick from the appropriate folder.
Related
Good day, I would like to ask what's the difference between creating a tablet layout variation and creating a folder for layouts (like: "res/layout-w600dp/" )?
I'm so sorry I'm new in making android app for small (cellular phones/android phones) together with large(tablets) devices.
Can anyone help me, please? I'm really having a trouble on what to do to have layout for tablets. I don't know if the layout for tablets will be automatically displayed when app is run on tablet or I have to put some code in the java part. I've read some documentations but I can't fully understand it. sorry.
Thank you for your help.
If you have two layout files:
res/layout/
activity_main.xml
res/layout-sw600dp/
activity_main.xml
And you have an activity that calls setContentView(R.layout.activity_main), you don't have to do anything else: the first version will be loaded on phones and the second will be loaded on tablets.
If each layout file has views with the same ids (maybe they're just arranged or sized differently), then you can just do whatever logic you want and it will work with both.
Normally, though, the tablet file will include views that the phone version does not. In that case, you should check to see if those views exist before trying to use them. Imagine that the tablet version has a view android:id="#+id/right_panel" and the phone version does not. You might write:
View rightPanel = findViewById(R.id.right_panel);
if (rightPanel != null) {
// do something for tablets
}
I have to make a new design for an Android App, but I only have to create the visual part (native Android). The app logic would be created by another guy based on what I present to him.
My question is? How would this be managed correctly? Do I have to make the XML's of each layout? How could I show the other person my progress?
What things should I consider when doing this?
Thanks
You need to mock the app first (create a prototype) as suggested by NoChinDeluxe. Then if you guys go ahead and decide to code it, the answer to your problem is separation of responsibilities. As Jeffrey said UI work is not only about layouts, but code as well. What I would suggest is that you and the other guy get together first and define some contracts (interfaces) that will allow you guys to split the work and work in parallel. Therefore, he can create the business logic of the app without worrying about the UI implementation. You, on the other hand, will have to mock that business logic he's implementing at the beginning so it doesn't block your UI work.
you could create layout XML files for all the Activities/screens, using resources (icons, etc as suggested by #NoChinDeluxe). However since you'd want to run the mock app, you might want to also create a "throw-away" Activity that allows you navigate to different screens of the app. Here you can add a number of buttons and when you click on each button, your app shows a specific activity. This way, you will be able to show your colleague all the screens you have created. I hope this helps.
This may not be what you want to hear, but creating Android layouts isn't a design task. They are closely tied to the code, and the design of them is going to depend on how the engineer chooses to implement the app.
Here's an example. You might have a grid with 4 cells. You could use a RelativeLayout, a LinearLayout, or GridLayout, or a GridViewLayout. Which will use choose?
I'd suggest providing your engineer with mockups and graphical assets where required. Let him / her take those and create the layouts. If you want to create layouts as a (visual-only) reference for engineering, great, but it's certainly a non-optimal tool for that task.
Things You will consider when doing visual part:-
You have to work on the resource folder of your application
Layout : All Layout you have to prepare.
Drawable : Images and drawable .xml.
Inside Values folder you will find
dimen.xml : For different devices dimen you can set.
string.xml : You can store string for hint or other purpose.
style.xml : For designing or theme or custom design.
color.xml : Color which are going to used in the application.
Doe's Android support multiple menu folder (e.g. like /drawable-hdpi and /drawable-mdpi)? If so what types are supported (land, xhdpi, swXXXdp)?
P.S. Sorry for such a goofy question...
Edit 1: For example I have different layouts. Depending on that I can have different menu resources, no? As a start it would be nice to have sooch folders:
res/menu
res/menu-land
res/menu-xhdpi
res/menu-xhdpi-land
res/menu-sw600dp
The first two work fine... but when I try to add the other ones the app work instable on different devices.
Yes. even in portrait and landscape modus:
menu-land-mdpi
menu-port-mdpi
menu-land-hdpi
menu-port-hdpi
menu-land-xhdpi
menu-port-xhdpi
yes. Don't see any point not to support it, documentation here provides no restrictions on it (I myself at least have used -land qualifier)
The menu can be used like layout folder, you can add menu-land, menu-port ... also, you can use specific menu for multi langue, like menu-fr, menu-en to rearrange items based on phone language...
I would like to have different activity.xml files for different orientations.
I have created a another folder with name layout-land. When I copy and paste the activity_main.xml file into it, then screen size is automatically getting oriented to landscape.
But after doing this, code assist is not working. Its showing the following error when I press ctrl+s
Content assist not available at the current location
what is the reason for this? Did I do anything wrong for creating different layouts for both orientation?
This sounds like an IDE-specific issue more than anything. The way you're doing it is correct. Assuming you a layout with the same name in as the other inside of layout-land, you should be good to go. Just give it a whirl.
Sounds like an Eclipse error to me (Googling "Content assist not available at the current location gives me a lot of hits); try running your application on a device and it will most likely work. It doesn't sound like you've done anything wrong.
There is already a similar question , but I am not satisfied with the answer
Can I put layout directory's xml file in different subdirectories in Android?
because there are too many xml files , if they are not into different group ,I can not find the specific one that I want .
Do you guys have any different method to solve this problem such as virtual group or something ?
As you can read in the linked question, and in the questions linked to this question, it is not supported to have custom folders inside the folders supported by Android.
You could clean up your files by following naming conventions, like layout_xyz.xml, image_abc.png, ...
I use the namespaceing technique,
i.e.
addnewrecord_main.xml
addnewrecord_custombutton.xml
addnewrecord_newbutton.png
search_listviewitem.xml
search_bgimage.png
etc