Android ListView ellipsize wide column content - android

I have a ListView that shows 2 columns per row. I don't have any specific column layout XML so Android is determining it for me. If the text in the 1st column is too wide then bad things happen to the layout of the 2nd column. Ideally I want Android to ellipsize the text in the 1st column at a sensible width and/or restrict the 1st column's width to 80% of the total displayable width. Can I do this in code?
Am happy to ellipsize the column 1 text itself manually when setting up the ListView if that's simple but it would have to cope with orientation changes (because in landscape the column 1 text would not be so wide as to have to ellipsize).
Thanks.

Set the width of your textviews to a specific width, ie, 50dp instead of wrap_content.
Then set ellipsize to true.
The rest should take care of itself.

Related

How to set row height of GridView fit to Screen in Android

I want to stretch the row of a GridView to match the height of the screen in Android.
How do I do this?
You are in control over your row heights, by virtue of what you put in
them. Since your cells appear to have more than one widget, they are
presumably wrapped in a LinearLayout or something. Set your
LinearLayouts to be some specific height, and the rows will all be
that height.
Personally, I think you should be resizing your images if you are
going to have text above and below each image on a per-cell basis.
With the Reference commonsware link

Android TableLayout Format

So I have a table layout that Im adding rows to through code since its not a constant table or a constant amount of rows. The problem Im having is right now my last column isnt fitting all the text because the middle row is set to stretch and its taking up most the view. Is there a way to set weights for the columns so that I can have the one row be bigger than the rest but still show everything else.
The problem Im having is right now my last column isnt fitting all the text because the middle row is set to stretch and its taking up most the view.
Then either change it so the last column is the stretch column, or list both (e.g., android:stretchColumns="1,2").
Is there a way to set weights for the columns so that I can have the one row be bigger than the rest but still show everything else.
By listing more than one in android:stretchColumns, the stretching effect is applied equally to all. You can think of this as the columns having equal weight.

Layout alignment in List Activity

I'm creating a list view in Android where each row is shown with LinearLayout. The problem that I have is that since the text is different in each line, it isn't aligned in the same way. See for e.g. the "Date" - in different position on each line. What is the best way to create such a view?
Thanks in advance,
Noam
This is the same problem why browsers are slow with showing tables with variable width: you have to calculate the widths after you've parsed all content.
The quickest way is to manually assign a size (width) to your columns.
If you really can't do that because your content is very unpredictable (are you sure?) you could try and find out what the sizes should be from all your content, and then award the sizes.
Have a couple LinearLayouts in your row layout. Set their orientation to vertical and their layout_width to fill_parent. Also set their layout_weight to 1. These will act as columns and when you put stuff inside and for example center it it will always be in the same place.

Table row wider than phone width

I have a TableRow with a decent amount of text in one of the columns. This text causes the table to be wider than the width of the phone, and so the right side of the data is cutoff.
I would like to wrap the text to the next row, but I can't tell how to do this. I tried setting singleLine="false", but that doesn't seem to do anything. Alternatively, I would be ok truncating the data, but there doesn't seem to be a great way of doing this either.
I ended up using a LinearLayout instead of a TableLayout. This does wordwrap by default and is close enough to TableLayout for my use.

Format buttons to fill parent based on dynamically added text

I'm hoping I can get some formatting help. I have a TableLayout. Inside the TableRow, I have 2 RelativeLayouts. Each RelativeLayout has 2 buttons in it that overlap (this is by design). The button text is dynamically added at runtime. This makes the buttons taller if the text is long enough. However, the text in one column (RelativeLayout) is different that the text in other column (RelativeLayout). So, the TableRow is expanded by the taller of the buttons. What I'd like is to have the smaller buttons fill in to the same size as the larger one.
I'm real new to Android development, but I've tried every combination of match_parent/fill_parent/wrap_content that I can think of, but none of them make the buttons stay the same size (that is, the size of the larger one). Some even expand the button to the full height of the screen (which I don't understand either...I'd think that the parent would be the TableRow and that would limit it)...
I appreciate any advice.
Use
button.setEllipsize(TruncateAt.END);
attribute while creating the buttons

Categories

Resources