If I have a linear layout with vertical orientation and e.g. 6 children layouts what is the standard way to make it into a tappable layout?
I.e. Show only 2 of the children and on tap expand to show all?
I can think of having 2 layouts one with 2 children and 1 with 6 and hide/show each one alternatively on tap.
Is there a more standard way?
Standard way to do it by using Expandable ListView.
You can find a working example here
It look like this
Related
I hit a brick wall trying to configure my app for multiple screens. I read a lot of information about it but so far I didn't manage to successfully do it. to begin with, I have to use hard-coded sizes for my buttons because there are many of them, 53 to be exact, and they have to be square, 40x40dp, and placed precisely on the layout. so I can't use wrap_content, fill_parent, etc' because then I can't fit all the buttons on the layout.
I've created 5 different layout 'activity_main.xml' with these screen configuration: normal_mdpi, large-hdpi, xlarge-xhdpi, xxhdpi, xxxhdpi. so far so good but if I don't apply (With the "device for preview" dropdown menu) a specific phone configuration to any of the layouts, then they won't fit on the screen. But then the layouts fit only for these phone configurations, they won't fit for one with a similar configuration but slightly different. what am I doing wrong? how many layouts do I need? do I need to create a layout for each phone out there?
You cannot use fixed sizes. I know you want to use fixed sizes, but you can't. Creating multiple layouts for each density is a common mistake. There is usually only one xml layout resource file for each activity, but there are exceptions when making really advanced layouts (fragments will be used).
How to fix the layouts
As the base layout inside the layout resource file, i suggest you use ConstraintLayout as it has a ton of potential and can easily make complex layouts. It will take some time to edit each view to make them use wrap_content or match_constraint (match_constraint is basically match_parent but for ConstraintLayouts), but it is necessary. Android will then take care of resizing and fitting the views for any density/screen size if you use wrap_content and match_constraint (match_parent for other base layouts like LinearLayout).
And remember, never use fixed sizes for views.
I started working on an android project which looks something like the image attached below.
I created a relative layout which should now contain two layouts. A linear which has a timer and a custom layout which should have a n*n grid layout.(say 8*10) horizontal layout.
I need to interact with grids like clicking on the grid should add an image to the grid etc. Is there a better way of implementing this rather than gridview?
Thanks
You can check GridLayout but I think GridView is better for this amount of fields.
So I have a Scroll View which contains a relative layout. I want that relative layout to have 3 or more layouts that can be scrolled. I know how to implement that with HorizontalScrollView, but before execution, I have no idea how many elements the HorizontalScrollView is going to have. Should I use ViewPager for this? What I would like the most is a HorizontalListView.
Would you recommend something like this:
https://github.com/sephiroth74/HorizontalVariableListView
Or should I add views programmatically in a HorizontalScrollView?
ScrollView is widget that should be used to keep static layouts inside. In general - ones that just are ~slightly bigger that the screen.
If you need something really dynamic you should use elements based on adapters like ListView, or ViewPager.
I am trying to create a layout that can fits my situation where I will need to have a layout that keeps the views like imageview or textview or probably a combination of a few. while on the top right of it, i will need to have two buttons on top.
However, this layout has to be dynamic where I can select whether if I want to show the buttons or not. How should I go about it?
You can use any layout you want really, although it sounds like a horizontal LinearLayout would fit your situation the best.
You can then control visibility of individual elements via setVisibility(View.GONE) and setVisibility(View.VISIBLE), or simply through addView.
How could I resize menu entries to have, for example, only one entry on the bottom row. Here is an example:
Notice how the "Add" and "Wallpaper" are both on the top and the others are on the bottom. How could I accomplish the same feat, but having just one menu entry on the bottom and two on the top?
I don't think this is possible, looking at the documentation there are no methods for Menu or MenuItem which would allow you to specify this kind of thing. In your supplied image Add and Wallpaper are listed first (you can specify the order of your menu items) and when there are 5 clearly Android automatically puts 2 on the top and 3 on the bottom.