Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

android - Remove space between stacked TextViews

I have a vertical LinearLayout with two TextView inside it. The former contains a static text property (it's text never change) and the last contains a regressive timer. The image below shows both items:

stacked textviews

I want to eliminate the blank space that both texts have both top and bottom. I've tried several approaches...

android:includeFontPadding="false"
android:lineSpacingMultiplier="1"
android:lineSpacingExtra="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"

...but none of them removed the space above the text. How can I make both texts close to each other without any extra space?

PS: I've found this similar question, but no one answered it.


Full layout code:

<LinearLayout 
    android:id="@+id/boxTime"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp" >

    <TextView
        android:id="@+id/textRemainingTime2"
        android:layout_width="wrap_content"
        android:layout_heigh="wrap_content"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        android:textSize="70sp"
        android:includeFontPadding="false"
        android:lineSpacingMultiplier="1"
        android:lineSpacingExtra="0dp"
        android:paddingTop="0dp"
        android:paddingBottom="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"
        android:text="@string/title" />

    <TextView
        android:id="@+id/textRemainingTime"
        android:layout_width="wrap_content"
        android:layout_heigh="wrap_content"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        android:includeFontPadding="false"
        android:lineSpacingMultiplier="1"
        android:lineSpacingExtra="0dp"
        android:paddingTop="0dp"
        android:paddingBottom="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"
        android:textSize="107sp"
        android:text="@string/timer" />

</LinearLayout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using negative margins. It may take a bit of playing with the numbers to get it right, but I've done it before and it worked out well.

android:layout_marginTop="-5dp"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...