[英]TextView: Remove spacing and padding on top and bottom
I have one textview which size is 50 dp.我有一个大小为 50 dp 的文本视图。 I got this result like the picture below.我得到了如下图所示的结果。
I want to remove bottom spaces in my textView ,because its height depend on the text size.我想删除 textView 中的底部空格,因为它的高度取决于文本大小。 And I want to receive background only into my quotation mark.而且我只想在我的引号中接收背景。 Is there any way to remove the unused spaces in my textView?有没有办法删除我的 textView 中未使用的空格?
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="top"
android:text="“"
android:fontFamily="@font/arialbd"
android:background="#ff0"
android:textColor="#E8E9EF"
android:includeFontPadding="false"
android:textSize="50dp" />
Try this:尝试这个:
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="top|center"
android:text="“"
android:fontFamily="@font/arialbd"
android:background="#ff0"
android:textColor="#E8E9EF"
android:includeFontPadding="false"
android:textSize="50dp"
android:gravity="top" />
This solution works on my case.此解决方案适用于我的情况。 To remove bottom padding.去除底部填充。 Set the layout_height
the same size as your textSize
or 1dp or 2dp less.将layout_height
设置为与textSize
相同的大小或小于 1dp 或 2dp。
Set includeFontPadding="false"
.设置includeFontPadding="false"
。 Set android:lineSpacingExtra="0dp"
设置android:lineSpacingExtra="0dp"
In your case you have to implement custom textView.在您的情况下,您必须实现自定义 textView。 check this example for reference.检查此示例以供参考。
U can try setting your bottom margin to a negative value.您可以尝试将底部边距设置为负值。
Something like this:像这样的东西:
android:layout_marginBottom="-10dp"
Let me know if its works, that is the simplest way but can be anothers...让我知道它是否有效,这是最简单的方法,但可以是其他方法......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.