【问题标题】:android reduce space between two vertical TextViews [duplicate]android减少两个垂直TextView之间的空间[重复]
【发布时间】:2011-08-23 14:18:47
【问题描述】:

我的应用中有两个垂直的 TextView 元素。 TextViews之间有很多空间,pading和layoutMargin都是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>         

.
.

感谢

【问题讨论】:

  • 显示你的代码,可能是因为 TextViews 父布局的设置
  • @Zsolt Safrany 这个问题较旧,重复只能是最新问题:)
  • @Jovan 没关系。他们问同样的问题,并且有一个解决方案。

标签: android android-layout


【解决方案1】:
android:includeFontPadding="false"

【讨论】:

    【解决方案2】:

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

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

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

    也可以参考this

    【讨论】:

    • 这是一个不受支持的解决方案。现在可以使用,但仍不受支持。
    【解决方案3】:

    您可以尝试为任何布局设置负边距。 就像你可以给第二台电视一样:-

    android:layout_marginTop="-10dp"

    第一部电视:-

    android:layout_marginBottom="-10dp"

    您可能需要根据需要更改值

    【讨论】: