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 last line in the right TextView?
I'm open to using whatever layout (RelativeLayout, LinearLayout, etc.) that can accomplish this.
(The default behavior of android:layout_alignBaseline
in Android is that it aligns the baselines of the top lines.)
for the new line in TextView just add \n in middle of your text it works..
Show activity on this post. Create a Custom View for Textview . Make the entry in the attrs. xml file and give an option to select Font as a list in custom TextView .
With the Justified option, only the first and last lines will be aligned to the baseline grid. If you adjust a text frame’s Top or Bottom Inset values in the Text Frame Options dialog box, you change the location of the first or last baseline, respectively. With the Selection tool, select a text frame. With the Type tool , click in a text frame.
To view multiple lines in the TextBox control Set the Multiline property to true. If WordWrap is true (the default), then the text in the control will appear as one or more paragraphs; otherwise it will appear as a list, in which some lines may be clipped at the edge of the control. Set the ScrollBars property to an appropriate value.
Once you’ve made your various design decisions, it’s just a few more steps to align your baselines across columns. Jot down your body text leading value. In my example, my body text is 12 point type on 16 pt leading.
Baseline alignment is a fairly easy task in InDesign. Place your multi-column story and set up the formatting for your body text, heads, lists, etc. Once you’ve made your various design decisions, it’s just a few more steps to align your baselines across columns. Jot down your body text leading value.
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.
public class BaselineLastLineTextView extends TextView {
// TODO: constructors, etc.
@Override
public int getBaseline() {
Layout layout = getLayout();
if (layout == null) {
return super.getBaseline();
}
int baselineOffset = 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 -->
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With