Android如何减少两个竖向TextView之间的间距

10
我在我的应用程序中有两个垂直的TextView元素。 TextView之间有很多空间,pading和layoutMargin都为0。
有没有办法减少这个空间?

On image space between two text views-padding and margin are 0

编辑 这是我的代码:

.
.

<LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="right"
            android:paddingRight="10dp"
            android:layout_weight="1">
                <TextView 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/text_size_extra_small"
                    android:textColor="@color/home_tab_text_normal"
                    android:text="Test1"/>
                <TextView 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/orange_text_color"
                    android:textSize="@dimen/text_size_large"
                    android:textStyle="bold"
                    android:text="Text2"/>


        </LinearLayout>         

.
.

谢谢


1
展示你的代码,可能是由于TextView的父布局设置问题导致的。 - Adinia
@Zsolt Safrany 这个问题比较旧,重复的只能是最新的问题 :) - Jovan
@Jovan 没有太大关系。他们问了同样的问题,那个已经有解决方案了。 - Zsolt Safrany
3个回答

18
android:includeFontPadding="false"

6

负边距可以通过两种方法设置 -

1)通过xml - 将“android:Layout_marginTop”字段设置为负值 - 其他人已经在上面建议过了

2)通过java(以编程方式) - 将LayoutParams的“topMargin”字段设置为负值。

您还可以参考此链接


这是一个不受支持的解决方案。现在可以工作,但仍然不受支持。 - methodsignature

3
您可以尝试通过为布局中的任何一个元素设置负边距来实现。 例如,对于第二个文本视图,您可以设置如下属性: android:layout_marginTop="-10dp" 或者 对于第一个文本视图,您可以设置如下属性: android:layout_marginBottom="-10dp" 您可能需要根据自己的需求更改数值。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接