How Do I Alignbaseline To Bottom Line Of Multi-line Textview?
I have two TextViews side by side. Let's say the left TextView is 1 line and the right TextView is 2 lines. Is there any way to align the baselines of the left TextView with the la
Solution 1:
You could accomplish this with RelativeLayout if you implement a custom TextView. Specifically, you could override TextView.getBaseline like so:
package mypackage.name;
// TODO: imports, etc.publicclassBaselineLastLineTextViewextendsTextView {
// TODO: constructors, etc.@OverridepublicintgetBaseline() {
Layoutlayout= getLayout();
if (layout == null) {
returnsuper.getBaseline();
}
intbaselineOffset=super.getBaseline() - layout.getLineBaseline(0);
return baselineOffset + layout.getLineBaseline(layout.getLineCount()-1);
}
}
Then you would use your custom TextView inside a RelativeLayout as follows:
<mypackage.name.BaselineLastLineTextView
android:id="@+id/text_view_1"
<!-- TODO: other TextView properties -->/><TextView
android:id="@+id/text_view_2"
android:layout_alignBaseline="@id/text_view_1"
<!-- TODO: other TextView properties -->/>
Post a Comment for "How Do I Alignbaseline To Bottom Line Of Multi-line Textview?"