Thanks, thats a nice solution. Useful diagram too.

However, I probably should have explained more about what I'm trying
to do, because if I understand you correctly, that solution does not
help what I want to do.

In my horizontal LinearLayout, there are actually two TextViews which
sit side by side one another (no gap). In the normal (i.e. not too
long text) situation the two TextViews are wide enough to fit all the
text on one line. However, when the text is too long then the text
needs to wrap and so I want to set the maxWidth of the first TextView
(or the minWidth of the second TextView).

Here is a two-item ListView I have. Each item is a LinearLayout
containing the two TextViews:

+------------------------------------------------------+
This is short | This is also short
+------------------------------------------------------+
This is not at all short | This is not so
so I need to wrap        | short either
+------------------------------------------------------+

If I don't use maxWidth then the second TextView is sometimes too
narrow.

On Oct 16, 10:19 pm, Streets Of Boston <[email protected]>
wrote:
> Wrap another Layout (ViewGroup) around your text-view.
>
> Set this new layout's width to 50% of the parent's width (using Weight
> (or WeightSum... i can't remember) of 100 in the parent and
> layoutWeight or 50 of your new layout. Then the child of your new
> layout, your text-view, has a layoutWidth of 'wrap_content'. You may
> need an extra new layout-out with layoutWeight of 50 as well, to make
> sure the total is 100.
>
> +------------------------------------------+
> |                                          |
> |                                          |
> |                                          |
> +-------------------100--------------------+
> |+-------50----------+-------50-----------+|
> ||                   |                    ||
> ||[TextView]         |                    ||
> ||                   |                    ||
> |+-------------------+--------------------+|
> ++-------------------+--------------------++
>
> On Oct 15, 11:24 pm, westmeadboy <[email protected]> wrote:
>
>
>
> > Thanks but (though maybe I've misunderstood) isn't that for specifying
> > the width as a percentage? I want to specify the maxWidth as a
> > percentage. The width just needs to wrap the content (but no more than
> > the maxWidth).
>
> > On Oct 15, 10:51 pm, RichardC <[email protected]> wrote:
>
> > > Took me a while to find it, original discussion 
> > > link:http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > > --
> > > RichardC
>
> > > On Oct 15, 3:19 pm, RichardC <[email protected]> wrote:
>
> > > > One workaround - you could put your controls into a horizontal
> > > > LinearLayout (with it's width set to fill_parent) and then set the
> > > > weights of each control inside the LinearLayout so that they total to
> > > > 100.
>
> > > > For example, if you had 3 controls inside the LinearLayout you could
> > > > use 10, 60, 30 for their weights.  That should cause the 1st control
> > > > to use 10%, the second 60% and the third 30% (total 100%).
>
> > > > Hope this works for you.
>
> > > > --
> > > > RichardC
>
> > > > On Oct 15, 12:19 pm, westmeadboy <[email protected]> wrote:
>
> > > > > Thanks for your help.
>
> > > > > I've looked into this a bit more and it seems that, for what I want to
> > > > > do, its enough just to define another layout in the layout-land
> > > > > folder.
>
> > > > > Its not perfect, because I'm currently assuming just two possible
> > > > > screen widths (320 and 480) and so setting the maxWidth accordingly
> > > > > for those two scenarios. This might need a little reworking with the
> > > > > new support of multiple screen-sizes in 1.6, but it will do for now...
>
> > > > > On Oct 15, 1:50 pm, String <[email protected]> wrote:
>
> > > > > > On Oct 15, 5:32 am, westmeadboy <[email protected]> wrote:
>
> > > > > > > For example, in the layout xml, is it possible to get a handle on 
> > > > > > > the
> > > > > > > screen width and apply some kind of arithmetic to it (e.g.
> > > > > > > maxWidth="(60 * @screenWidth) / 100px")
>
> > > > > > AFAIK, no calculation is possible in the XML. I'd recommend doing 
> > > > > > this
> > > > > > in your activity's Java code instead, using the TextView.setWidth()
> > > > > > method.
>
> > > > > > > Also would this approach mean the maxWidth would be automatically
> > > > > > > recalculated on orientation changes?
>
> > > > > > If you do it in Java, you can handle this yourself, as the activity
> > > > > > gets recreated when the orientation changes.
>
> > > > > > String- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to