简体   繁体   English

TextView去除了顶部和底部的填充,以便于对齐?

[英]TextView strip away top and bottom padding for easier aligning?

I'm trying to align the top of a TextView (which will always be an integer greater than 0) and an ImageView. 我正在尝试对齐TextView(它将始终是大于0的整数)和ImageView的顶部。

Padding the top of the Imageview by 4dp was very close, but it is an inexact solution. 4dp填充Imageview的顶部非常接近,但这是不精确的解决方案。

The culprit is this: 罪魁祸首是:

数字填充

Disregard the padding to the left. 忽略左侧的填充。 The padding above the number and below the number are frustrating. 数字上方和下方的填充令人沮丧。 Is there any way to have the top and bottom completely wrap around the number? 有什么方法可以让顶部和底部完全包裹住数字吗? I suppose the issue will come from 4, 5, 6, 8, 9, etc. potentially having different upper limits, but is there a way to handle this? 我认为问题将来自可能具有不同上限的4、5、6、8、9等,但是有没有办法解决? android:includeFontPadding=false gets rid of something of the padding, but it doesn't get rid of it all. android:includeFontPadding=false摆脱了某些填充,但并不能完全摆脱。

XML: XML:

<TextView
            android:id="@+id/commentsCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="8dp"
            android:layout_marginRight="4dp"
            android:textColor="@color/blue"
            android:visibility="visible"
            android:text="4"/>

        <ImageView
            android:id="@+id/commentsCountBubble"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_comment_bubble"
            android:visibility="visible"
            />

Wrapped in a standard LinearLayout. 包装在标准LinearLayout中。

Edit: Also note that the padding around the Imageview wraps the content completely (basically, there is no padding). 编辑:还请注意,Imageview周围的填充完全包裹了内容(基本上没有填充)。

Try this: 尝试这个:

<TextView
    android:id="@+id/commentsCount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/ic_launcher"
    android:drawablePadding="8dp"
    android:layout_marginRight="4dp"
    android:textColor="@color/blue"
    android:visibility="visible"
    android:text="4"/>

If your views are placed on RelativeLayout you can use that on your TextView : 如果您的视图放在RelativeLayout ,则可以在TextView上使用它:

android:layout_alignTop="@+id/yourImageView"

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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