I checked android docs, but didn't really find an answer on how to show custom layout in my application. I'm thinking of custom fragment placed next to navigation drawer. Maybe someone can give me pseudo code for better understanding? Thanks.
Visual representation:
http://imgur.com/a/VwTvs
On specific itemClick I want to make a layout (that contains icons/pictures) and place it next to nav drawer.
The key-word you are searching for is resource buckets. Essentially you can create resource-folders based on screen size, API version, orientation and such. Refer to the official documentation on how to create layouts for different screen sizes.
In Android Studio you can create resource-files based on those quantifiers by open the "new resource file" dialog and selecting the quantifiers you want in the lower part of the dialog.
Have a look here to read on layouts made exclusively for TVs.
Related
I m new to Android development and stuck with design. I d like to design a single activity application with multiple fragments. But whatever I consider, I m stuck with design.
I first considered fragments as components or widgets that I could organize where I wanted on my screen. But a single activity has only one xml view layout and can not find a solution.
Here is what I want.
UI design
The problems are the following.
The layout choice: I need a layout for full screen fragment screen 1 but another splitted one for other screens.
The keyboard: if I do a fullscreen fragment layout for all my screens with a (game-keyboard) fragment and (dico-keyboard) fragment, how do I remove the keyboard in dico fragment on tablets ? And can I share keyboard code between both fragments ?
I saw that calling setContentView during runtime is kinda annoying as you have to reassign your variables and is not suitable.
All the applications I find are fullscreen single fragment on layout allowing libs like ViewPager. I can not find an example of composed screen with fragment components.
What layout would you chose, with what kind of fragments ?
Or do you know a library that allow composing fragments as widgets on screen ?
Thanks for your help.
Welcome to Android. Buckle up, it's going to be a bumpy ride.
First, you should spend some quality time with the Android Developer Guides.
Developer Guides | Android Developers
The insight for your particular challenge is that layouts are resources, and and you can have a layout resource that changes based on the configuration.
So for example, you could have a resource like layout_main with one XML file for small devices and a different XML file for large devices.
App resources overview | Android Developers
Create alternate layouts | Support different screen sizes | Android Developers
You can arrange fragments on a layout using the Android Studio layout designer.
You can add Fragments and navigate.
First of all yu need a navigation: In the left hand side on Android Studio you can find the Resource Manager Then click to Navigation then click to + and choose the Navigation resource file
After this you can add fragment to the navigation:
New Destination (green +) (Don't forget to give name to your fragments).
After this you can add the navigation to your activity's xml. You should use the app:menu=”#menu/bottom_nav_menu” code in your xml
Here a video about the process:
https://www.youtube.com/watch?v=Chso6xrJ6aU
Is there a quick and easy way to see how my application will look on different screen sizes and shapes? Currently, I'm going into the AVD manager, editing my device definition, and then launching a fresh emulator. It takes maybe ten minutes for each one.
They layout is defined entirely from resource files. I don't actually need to execute the app. Is there a faster way to do this?
Edit: I should add: there are some custom widgets in the app.
While looking at a layout open the "Design" tab or open the "Preview" tab on the side. On the top of the window you will see a list where you can change the layout and orientation.
May not solve your entire issue, but it's a good to know.
If you want to have a preview of a static page (not rendered at runtime, like recyclerview), you could use android studio to do that.
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 have used localization in my android application. Which supports two kind of layout in application.
I have used Fragment and Fragment Activity in my application.
If language is English then layout should be aligned to left as shown in image below.
And if language is Hebrew then layout should be aligned to right as shown in image below.
I am trying to load this layout by two different layout files and then I can detect which language and I can use appropriately.
Is there any other good methodology through I can use achieve this functionality without creating different XMLs for all layouts?
Can anybody please help me to resolve this issue?
This should help:
http://developer.android.com/about/versions/android-4.2.html#RTL
Android supports right-to-left layouts natively since android 4.2.
Creating two similar layouts those are having same #+id values is a clean approach but if you don't want to create two different layouts then you could simply set the layout_gravity attribute by code with some helper method and by getting the LayoutParams of the containers you are using in your xmls.
Edit :
From another answer , If it works for you with the support package i.e. v4 if you are targeting 2.2+ above then this would be an awesome approach to go with.
http://developer.android.com/about/versions/android-4.2.html#RTL
just came to know about this. Android is awesome!!
I want to create a layout like the below picture. How can I set the drop-down like this with cancel option. I am using spinner to show the drop-down but cannot set the layout like this.
Can anyone help me to create a drop-down like this. I also want to create an expand button for a list item which will open the content in a new page. My aim is to set all the available settings in a single page.
Then use PreferenceActivity. In fact, that's a standard preference screen.
http://developer.android.com/reference/android/preference/PreferenceScreen.html
http://jetpad.org/2011/01/creating-a-preference-activity-in-android/
You can take a look at the API Demo app which is in the Android SDK. There you can learn how to create this kind of screens (either from XML or code). It has many advantages... for instance, you won't have to worry about persisting the settings... the OS will do that for you.