【问题标题】:TextView gets smaller when containing two lines of text包含两行文本时,TextView 变小
【发布时间】:2011-11-18 02:46:56
【问题描述】:

我有一个简单的水平线性布局,里面有四个相同样式的 TextView。当 TextView 中的文本需要两行时,TextView 会变小:

我不明白为什么。有人可以帮忙吗?

谢谢

布局

<LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp">

    <TextView style="@style/compte_ba_cell"
        android:background="@color/grey_header"
        android:textStyle="bold" android:text="@string/montant" />

    <TextView style="@style/compte_ba_cell"
        android:background="@color/grey_header"
        android:textStyle="bold" android:text="@string/origine" />

    <TextView style="@style/compte_ba_cell"
        android:background="@color/grey_header"
        android:textStyle="bold" android:text="@string/echeance" />

    <TextView style="@style/compte_ba_cell_last"
        android:background="@color/grey_header"
        android:textStyle="bold" android:text="@string/statut" />

</LinearLayout>

风格

<style name="compte_ba_cell">
    <item name="android:layout_width">71.5dp</item>
    <item name="android:layout_height">50dp</item>
    <item name="android:textColor">#000000</item>
    <item name="android:background">#FFFFFF</item>
    <item name="android:layout_marginRight">2dp</item>
    <item name="android:textSize">12sp</item>
    <item name="android:typeface">serif</item>
    <item name="android:gravity">center</item>
</style>
 <style name="compte_ba_cell_last" parent="@style/compte_ba_cell">
    <item name="android:layout_marginRight">0dp</item>
</style>

【问题讨论】:

    标签: android textview


    【解决方案1】:

    如果您将第三个 TextView 更改为包含 android:layout_height="fill_parent",这将解决您的问题。我想问题来自与“wrap_content”有关的东西,但我不确定这是否是 layout_height 的默认值。也没有意义,为什么在其他情况下,它不会环绕内容并且更小。

       <TextView style="@style/compte_ba_cell"
            android:background="@color/grey_header"
            android:layout_height="fill_parent"
            android:textStyle="bold" android:text="@string/echeance" />
    

    【讨论】:

    • 你是对的。如果我将android:layout_height="50dp" 设置为我的LinearLayout 并将android:layout_height="fill_parent" 设置为我的TextView,它就可以工作。很奇怪。
    【解决方案2】:

    当为 textview 提供的宽度或高度不足以容纳您的文本时,通常会发生这种奇怪的事情。 无论如何,我建议您根据您的要求为线性布局提供高度和宽度,并且对于您的 textview,高度和宽度都应该是 fill_parent。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      相关资源
      最近更新 更多