Android HorizontalListView which respects wrap_content - android

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?

Related

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.

Android - How can I determine an appropriate height for my ListView items?

I am building an Android app with a ListView. Coming from iOS I am used to setting fixed pixel heights for list view items, since the screen sizes of the used devices are always the same. Now for Android, I am wondering what is a good way to dynamically set the heights of ListView items so that it it looks nice on all screen sizes?
In android there are two famous properties. They are:
MATCH_PARENT formerly FILL_PARENT using this property for layout width or height will expand the view to the parents width or height minus margins
WRAP_CONTENT using this property for layout width or height will allow the view to take as much space required or available(if it exceeds screen dimension exception is inside scrollable views)
So for your tag set both width and height to match_parent. And in the custom row that you might be populating set the root layout width to match_parent and height to wrap_content.
Note: in android while we give fixed height at times but it is generally not a good practice.

MATCH_PARENT inside WRAP_CONTENT is giving me problems

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

How to make buttons, with dynamic text, the same size and width to height ratio?

I have a few buttons I want to display in a row in a decision tree. I'm trying to get the buttons in each row of the tree to be the same size. But the buttons have different text. Some have a couple words and some have a sentence. Is there a way I can get the buttons to all be the same size and all maintain the same width to height (4:3) ratio?
I can get the heights the same using fill parent on the button heights while having the parent row layout_height set to wrap_content. How can I get the width of the buttons to be the same size while maintaining a 4:3 width to height ratio. (The width to height ratio constraint is so I don't end up with really tall and thin buttons, which would look silly)
Anyone have any suggestions?
Edit:
I just saw this link which is kinda what I am looking for: Scaling layout with invariant aspect ratio in Android
My problem with this is that it will inflate all the buttons and introduce a lot of empty space around the text inside.
If I could find a way to incrementally increase the width or height (whichever is smaller) of the button and then resize it so it re-"wraps_content", then this could work. Anyone know how to re-wrap the content?
If you are able to get the same height for all you can use android:layout_weight="1" for all buttons and put android:layout_width="0dip" so all buttons will have same width

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