Android Layout - Align To Right Without Wrapping And Reserving Space
Solution 1:
I think this is the layout you're after:
publicclassTableLayoutCustomextendsTableLayout {
publicTableLayoutCustom(Context context) {
super(context);
this.setColumnShrinkable(0, true);
this.setColumnStretchable(1, true);
TableRowrow1=newTableRow(context);
TableRow.LayoutParamslp=newTableRow.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
TextViewtitle=newTextView(context);
title.setText("Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum ");
title.setId(1);
row1.addView(title, lp);
lp.setMargins(20, 0, 0, 0);
TextViewtag=newTextView(context);
tag.setText("TAG ME");
row1.addView(tag, lp);
this.addView(row1);
TableRowrow2=newTableRow(context);
TableRow.LayoutParamstlp=newTableRow.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tlp.span = 2;
TextViewdescription=newTextView(context);
description.setText("Description here");
description.setId(2);
row2.addView(description, tlp);
this.addView(row2);
}
}
If you change the text on the title to something shorter you will see that the tag
"follows" the title
.
Solution 2:
after a few more tries, including a linear layout with a table layout enclosing the title and tag, and the description as a child of the linear layout, i'll post what I'm using for now.
while this comes close, i'm still open to a better answer:
using right margin on the title and negative left margin of an equal amount on the tag does accomplish the basic idea, it assumes I know the size of the tag. If I allow say 100 pixels, and the tag text is longer than that, it'll wrap. This isn't a huge deal for this particular setup (since I have a predictable set of tags), I'd still be interested to know the "correct" approach.
Post a Comment for "Android Layout - Align To Right Without Wrapping And Reserving Space"