MATCH_PARENT inside WRAP_CONTENT is giving me problems - android

I have a bar in the bottom of my layout which consists in a horizontal LinearLayout (like a row) that contains vertical LinearLayouts (Like a cell of a row).
The Horizontal linearLayout (row) haves WRAP_CONTENT height because i want the bar fit its elements height, and the vertical linear layouts (cells) have MATCH_PARENT because they can have for example a item centered vertically inside,
so they are MATCH_PARENT and they must have the Height of the higher height of the cells on the row.
The problem is that the bar is occupying all the height of my screen. I think that there are problems with MATCH_PARENT inside a WRAP_CONTENT.
How can i solve this problem?

To set MATCH_PARENT height to LinearLayouts(cells) you must have to fix some height of row(LinearLayout) otherwise it will covers entire screen

Related

Determine responsive heights of children in a vertical LinearLayout inside of a ScrollView

I want to give responsive height to children in a vertical Linearlayout for example(some view height must be 25% of the screen height) I know this is simple if I use weight but the problem is that I have the LinearLayout inside a ScrollView this means I dont know the exact height of the LinearLayout so weight doesn't work here.can anyone give me a way to do so.
Use:
scrollView.setFillViewport(true)
This way, the linear layout inside occupies the full height.

Force LinearLayout child to use all available space but at least enough to fit its content

I'm struggling with getting LinearLayout to behave like I want it. Unfortunately, both dimension modes MATCH_PARENT and WRAP_CONTENT don't seem to fit for my purposes.
Here's why: I want the child that is added to the LinearLayout to be completely visible. Nothing should be cut off. So normally, I should use WRAP_CONTENT to achieve this behaviour.
But, if there's more space in the LinearLayout than the child really needs, I also want it to fill that space. This is of course what MATCH_PARENT is for.
However, I can't use MATCH_PARENT because in case there is less space in the LinearLayout than my child needs, using MATCH_PARENT will cut off the child which I don't want.
So this leaves me somewhat puzzled as to how I can achieve what I want: How can I allow a child to fill additional space in the LinearLayout (if available) while at the same time forcing the LinearLayout to be at least as big as the child needs in order to be completely visible?
Put your child view inside a ScrollView with width MATCH_PARENT, height MATCH_PARENTand set both the child's dimensions MATCH_PARENT
Instead of using MATCH_PARENT for your child, use WRAP_CONTENT and set your child's weight to 1,So it will take all the empty space in your LinearLayout. Suppose your LinearLayout's height is 128dp, and your child 's height is 56dp, your child will be 128dp . If you set WRAP_CONTENT on your LinearLayout, it will be 56dp, and it child will still take all the place it needs.
If you want your LinearLayout to have a minimum width or height, and not match_parent, you can do setMinimumWidth() or setMinimumHeight() in your xml layout or in your code programmatycally depending your childs default height and width.

Center the items of listview horizontally

I have a ListView whose single item have a RelativeLayout which contains many elements , now i have RelativeLayout set to wrap_content in height and a certain width. What i want to display is horizontally center the RelativeLayout. ListView spans horizontally and vertically to full as it has also wrap_content in height and width.
Also i don't want to include another layout.
Change RelativeLayout width to match_parent. and manage all inner views as yout require.

Android HorizontalListView which respects wrap_content

I need a horizontal ListView to be in the center of the screen.
And to become scrollable only if content's size is larger than screen's size.
I found this question
This lib is recommended, but when I set width to wrap_content, it ListView behaves like it was set to match_parent. So my items are always on the left edge.
Can anybody give me some advice?

Make last view fit to bottom of screen

is there any possibility to change the properties of the last view in the layout to change its size to fit to the bottom of the whole screen (in any screen density).
Here is a sample image of my layout:
The layout contains a ScrollView with a LinearLayout as only child. The last item in this LinearLayout is a TableView with a grey gradient as background.
You can try setting layout_height of your items to "fill_parent" and change their sizes via changing layout_weight property, that should work.
If you want the grey part to stick to the bottom you should put weight=1.0 and wrap content for height on the view that is above that one (the white area).
Checked it again on similar layout. The main work does the property android:fillViewport="true" Which
Defines whether the scrollview should stretch its content to fill the viewport
More infos: ScrollView.html#attr_android:fillViewport

Categories

Resources