Android TextView斜体和wrap_contents

10

我正在使用三个具有不同颜色的斜体文本视图

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:orientation="horizontal" android:id="@+id/submittedBy" android:paddingTop="10dip">


            <ImageView android:id="@+id/subByImg"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:gravity="left" android:layout_gravity="bottom" android:src="@drawable/submitted_by_arrow"/>
            <TextView android:id="@+id/submitLabel"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:gravity="left" android:text="Submitted by"  android:textStyle="italic"
                android:textSize="12sp" android:textColor="@color/gray" android:paddingLeft="5dip"/>
            <TextView android:id="@+id/submitName" android:textStyle="italic"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:textSize="12sp" android:textColor="@color/maroon_dark" android:paddingLeft="10dip"/>
                <TextView android:id="@+id/submitByDate" android:textStyle="italic"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:gravity="left"
                android:textSize="12sp" android:textColor="@color/gray" android:paddingLeft="10dip"/>
            </LinearLayout>

我想知道为什么每个字符都不能正确显示,特别是在中间显示的名字“Dan Buckland”,缺少了最后一个字符,看起来像“Dan Bucklano”。

另外,请告诉我如何同时使文本视图具有斜体和粗体。

alt text http://www.freeimagehosting.net/uploads/953d573113.jpg

3个回答

7

我曾经遇到同样的问题。通过在需要斜体的字符串末尾添加一个空格,我成功地解决了这个问题。

虽然这可能不是最长远的正确解决方案,但对我来说有效。


1
没错,那个可行。可以使用一个额外的空格或将宽度设置为“fill_parent”。遗憾的是,Android(我的版本是2.3.7)没有正确处理这个问题。 - shkschneider
1
如果您正在使用XML,则必须使用\u0020来强制添加空格。 - Oleg Vaskevich

2
似乎当使用斜体时,边界框计算不正确。
您是否尝试为元素使用paddingLeft = 6和paddingRight = 6? (重叠的可能性较小)。
有关TextView中多个样式的信息,请参见在TextView中是否可以使用多个样式?

1
你可以在string.xml文件中使用&#160;与文本一起使用。

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