【问题标题】:wrap_content leaving extra height when wrapping @stringwrap_content 在包装@string 时留下额外的高度
【发布时间】:2013-02-04 18:48:47
【问题描述】:

我有一个高度设置为 wrap_content 的 TextView - 但是,它在我的应用程序中留下了很多额外的空间。

来自 textview 的文本来自 @+string,似乎 wrap_content 将其高度设置为字符串变量的高度,而不是插入的实际文本。

如果我替换

            android:text="@+string/introGetStarted"

            android:text="Let's get started!"

然后它似乎显示了正确的高度并只包裹了文本。

我错过了什么吗?

我的完整TextView,供参考:

   <TextView
        android:id="@+id/textViewTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/d15"
        android:layout_marginRight="@dimen/d30"
        android:layout_marginTop="@dimen/d25"
        android:lineSpacingExtra="-10sp"
        android:text="@string/introGetStarted"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="@dimen/d70" />

【问题讨论】:

    标签: android textview


    【解决方案1】:

    您引用的字符串资源错误。去掉加号

    android:text="@string/introGetStarted"
    

    @+string/ 表示添加名称为“introGetStarted”的新字符串资源,而@string/introGetStarted 表示引用现有资源“introGetStarted”

    【讨论】:

    • 好的,我现在看到实际的字符串显示在我的图形布局选项卡中......但它仍然占用同样多的空间。用字符串本身替换字符串引用会缩小空间。
    • 尝试为您的 TextView 设置 android:padding="0" 属性。
    • 发布你的整个 layout.xml 以便我们看看还有什么问题。我在之前的评论中弄错了,应该是 android:padding="0dp",而不是 "0"。
    • 在上面添加了我的 textview,整个文件都可以在这里找到:pastebin.com/Pkp6mfeu
    • @jlbruno 你确定 TextView 太大了吗?也许您将其底部边距作为其中的一部分?尝试设置 android:background="#ffff0000" 你会看到它实际占用了多少空间。
    【解决方案2】:

    我实际上找到了答案,这是由于 strings.xml 文件本身出现了换行符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-07
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      相关资源
      最近更新 更多