Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.)

like image 654
Gus Avatar asked Oct 10 '14 19:10

Gus


People also ask

How do you get to the next line in TextView?

for the new line in TextView just add \n in middle of your text it works..

How do you customize TextView?

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 .

How do I align a text frame to the baseline grid?

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.

How do I view multiple lines in a text box?

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.

How do I align my baselines across columns?

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.

How do you align baselines in a story in InDesign?

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.


1 Answers

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 -->
/>
like image 189
pscuderi Avatar answered Nov 08 '22 19:11

pscuderi