简体   繁体   中英

Why multiline TextView and two single line TextView's height is different?

I want to synchronize these views

  1. Two TextView

图片1

  1. One TextView with two lines

图片2

Two TextView's height is 73 * 2 = 146

But, One TextView is 155.

I want to show same layout for these views.

Why these views are different?

Here is my code

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:bufferType="spannable"
        android:ellipsize="end"
        android:lineSpacingExtra="5.5dp"
        android:textColor="@color/grey900"
        android:textSize="15.5sp" />

Because it includes some situation,

  1. different padding
  2. different margin
  3. different lines-pacing

as above will make different total height with them.


In case 1 You use two TextView, total height depends on

textHeight*2 + padding-bottom*2 + padding-top*2 + margin-between-them


In case 2 You use single multiline TextView, total height depends on

textHeight*2 + padding-bottom + paddingTop + line-spacing


You can see that variables make different height are paddingmarginline-spacing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM