I have multiple fragments that share the same layout which is a RecyclerView inside a LinearLayout. In the past, I had files like:
fragment_one.xml
fragment_two.xml
fragment_three.xml
fragment_four.xml
Though, I am currently questioning if it is better, to use a single layout named, for example, fragment_generic. Is this a good or bad idea?
Thanks.
It actually depends on your use case. If you have like 5 fragments which have the same layout i.e a single recyclerview list. It is better to use a single layout for all the purposes. That makes the application really compact.
Later, when some changes come into place and you want to add item , let's suppose a fab icon, then create a new layout and use it for the changed fragment only.
So about your question, yes it would be the best idea to use the same layout for these 4 fragments.
Related
I'm trying to make an app and I have made a blueprint for a specific activity, but I don't know how to implement it. The layout contains few buttons at the top of the activity, and each button features some information, which is displayed inside the view. The view which needs to be updated is present under the buttons. I don't want the activity to be changed, instead it should update the contents of the View, which is different for each category/button.
By doing some research I have realised that the "Tab Layout" can be used to achieve my requirements, but I don't want the tabs and I need some stylish buttons as a replacement.
I know I'm not the best at describing, so I have looked upon Dribble and found one design which is 100% similar to blueprint.
I want to achieve this using XML and Java using Android Studio! Every suggestion will be a great support foy my app.
Thanks a lot.
As far as I know, you could achieve that by using fragments (which is the same concept you would have used on TabLayout). I don't really know how much knowleadge you have on Android, but if you know what a Fragment is, it should be easy for you to recreate the idea.
You have 3 buttons for 3 different fragments, so you must design every fragment by separate and change it depending the button you click.
I need to create the layout as shown below. What would an optimal way of implementing the adapter for this? Should I use a single RecyclerView and assign the different adapters when searchView is focused and un-focused? Or should I use 2 RecyclerViews and show one while hiding the other? .
I understand that this may not be a very specific question, but I didn't want to risk implementing something which would not work optimally in the end. Any other suggestions are also welcome.
My application has several screens, and each of them has almost the same layout.
I know I can use the "include" tag in xml to avoid rewriting the same layout again, but I also do not want to duplicate the java code of setting the behavior/properties of views and layouts.
What is the best practice to be more organized in this case?
Edit: For example in several screens, the first half of the layout is a gallery that scrolls horizontally with text below it. This is the same throughout my app
If the screens are the same for example. Activity/Fragment
You can create a "generic" parent that handles the logic and use include for the layout.
Or
Create a custom view that uses a layout as content and you can write your logic there.
I create a library that uses this principle.
here is a tutorial on how to create a view with a layout file
I have more than one XML-layout on my app and i am looking for a way to change the order in which my XML-layout displays when running my app
like which one of the layouts is displayed first ?
I think I didn't understand your question exactly but you can have as many as layouts you want. your activity shows the layout inside oncreate with setContentView(R.layout.yourLayout). If you want some particular parts in your layout, you can use fragments.
I am building a two column application for Android and I'm wondering how to do the navigation. The left column is the navigation bar. The right one is the content view. Both of them are LinearLayouts.
I have a different activity for all the options. How do I implement my menu into these? It is the same for all the activities (except the current one is highlighted), so copying the same code multiple times seems waste and makes it harder to change it later because I would have to change all the files.
I also have to change the title for every activity.
The typical answer would be Fragments. Here's a great tutorial on that topic.
However, depending on the triviality of your requirements, you could also consider using a horizontal LinearLayout containing your two original LinearLayouts.
in my opinion you should use fragments for your columns.
http://developer.android.com/guide/components/fragments.html
you Should use Fragment control for this. you can call content Fragments on right side (Content View) area with the click on leftSide(Content item/Index) .
I feel you should follow this link.
http://developer.android.com/training/multiscreen/screensizes.html
Am not sure but hopes u asked for the same.
Thanks..