I have 2 textviews per horizontal linearlayout row on two rows. All the views are set as 0dp width and weight 1. They all have the same font and text size etc.
The views on the left side are gravity aligned left and the two on the right are gravity aligned right.
When both textviews text length overflow android always gives precedence to the textview on the right and ellipse the views on the left.
Is there a method that can be used to control which view ellipses when both views on the same row would not fit.
Ideally I want the views on the right to ellipse in favor of those on the left. Or failing that make them ellipse evenly per row.
thanks
i don't think there is a feature of order of the views to manage how they are measured.
you can customize the linearLayout by extending it in order to support this feature , but this is too hardcore for this task .
i would suggest putting the problematic views (those that take too much space and you don't with them to take too much space) into a new layout , and set its width to match_parent .
this way , it should take the rest of the space at the end of the measurements of the other views ,
Related
I have two scroll views in a vertical linear layout.
I want them to be relative to each other so that they fill the entire linear layout and compensate if one cant cover half the screen.
Lets call that scroll views TOP and BOT.
If the screen can display 4 rows and both scroll views have infinite rows, each scroll views should display 2 rows and be able to scroll down to se the rest rows.
If TOP has 1 and BOT infinite rows, BOT should be resized to 3/4 of the linear layout.
If TOP have infinite and Bot has 1 row TOP should still just display 2, i.e. it should never pass the linear layouts vertical center.
Here are some pictures for reference:
my setup with weight set to 0.5/0.5.
result of 0.5/0.5 weight. Notice the gray bar above the BOT title bar. This empty space should be filled by the BOT bar.
if Using fixed size or wrap content the TOP will push the Bot out of view.
How can I have them hugging each other and still set TOP to a maximal height?
Preferable in XML.
Its better to set the weight dynamically. Count the number of items in both views. Set the weight of each view according to the ratios of their number of items. You can refer set weight dynamically for setting weights at run time
I have a TextView that I want to have 1/8 of the whole screen, and dp just works to get half of the height but how do I get the 4 TextView's to each share the bottom half of the screen equally?
Right now they share the height equally, but the ones on the left are wider than the ones on the right.
Inside of your RelativeLayout you need to make a horizontal LinearLayout just for these TextView's. Then to make them all take up an equal amount of space, assign an equal weight to them all with weight="1".
If you want a TextView to take up more or less space than the others, just assign a proportionate weight to it. For example if you have 4 views and want the first one to take up 1/2 of the space and the other 3 to share the rest equally, set the weight of the first view to 3 and the others to 1.
You can't with a relative layout- consider a PercentRelativeLayout
I'm trying to implement a tabular layout that has a header and a bunch of rows underneath it. I've chosen the GridLayout (android.support.v7.widget.GridLayout) as there's some requirements for some elements to span multiple columns (but those are of no concern to the question).
My header cells each contain a LinearLayout with a bunch of TextViews, they're dynamically filled in code,for the sake of example, have a look at the image below.
The second row should contain the divider which is a simple view, that should span my header columns (3).
The problem is the width of the divider - if I choose MATCH_PARENT, it will push the GridLayout to fill the whole remaining space to the right. The grid needs to wrap the content and center itself horizontally. It seems to me there's a conflict between the grid's layout (WRAP_CONTENT) and the divider's layout (MATCH_PARENT).
How can I fix the width of the divider without hardcoding it?
http://i61.tinypic.com/2415eg5.png
In red, my LinearLayouts (header), green, the GridLayout itself, the thin blue line at the bottom is the divider.
Thanks,
MO
SOLUTION (as provided below):
I had to set the column weight for the divider to 1, without specifying a width (actually setting it to zero). Because of my specific requirement to handle all of these in code, the solution was to manually instantiate the GridLayout.LayoutParams class and use
ColumnSpec = GridLayout.InvokeSpec(row_index, num_spanned_cols, weight)
Hope this helps others in the future.
If you set the width to 0dp then give it android:layout_weight="1"
(you could give it any weight you want) it should fill all the available space and not push your bounds if I understand what you are asking correctly
I have a horizontal layout to display 5 icons.
I would like to know if there is a way to display the first one always X dp from margin left and the last one X dp from the margin right and the others with the same space between then.
With LinearLayout the space is always the same even when I change the device , so sometimes my horizontal row became much more bigger than the space that the icons use and with RelativeLayout i just can align 3 items in this way ( alignParentLeft, centerInParent, alignParentRight)
With RelativeLayout I think you can easily put three of your icons at the proper place. For the last two icons, I don't think there's something you can do in your xml. Actually I have met the same problem before.
An approach is (maybe not the best one) to calculate the margins of the two icons in your java code. It's really easy to get the parent view width (in pixels) and you know how much space(a percentage) there should be before/after your views. Just a multiplication and addView with LayoutParam is sufficient.
A LinearLayout with android:width="match_parent", android:layout_marginRight and android:layout_marginLeft within a RelativeLayout should work.
The Linear Layout will be xdp from the left and xdp from the right, with the icons spaced evenly inside.
If you use the Linear Layout, you can use the weight attribute to calculate the correct spacing between the images.
Set each of their weights to 1 so that they take an equal space in the row :
android:layout_weight="1"
I hope that can assist you.
I have a vertical, set height (300px) LinearLayout (LL) with 3 nested LLs. 1 and 3rd are set with android:layout_height="wrap_content" and the middle one with android:layout_height="fill_parent". To my dismay, 3rd LL gets pushed out with 2nd one filling parent layout right to the bottom. How do I achieve desired effect since I want potentially resize the outside container with the middle portion expanding and contracting to accommodate the change
Turned out (Thanks Mark Murphy for the answer) that all I was looking for was to set middle row to
layout_height="0px" and layout_weight="1"
If, after all the wrap_content and fixed-sized items are allocated for
along an axis (horizontal or vertical), there is still room on that axis
left over, LinearLayout then allocates the remaining space to those
widgets with specified weights, in proportion to the weight.