2010-02-16 29 views
9

我使用3个用不同的颜色的Android TextView的斜体和wrap_contents

<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> 

我不知道每一个最后的字符无法正常显示特别的名字显示在中间斜体textviews是“丹·巴克兰”,它是缺失的最后字符看起来像 “丹Bucklano”

还告诉我,PLS怎么能有TextView的斜体和大胆的两个..

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

回答

1

似乎使用斜体时边界框的计算不正确。

您是否尝试过对元素使用paddingLeft = 6和paddingRight = 6? (减少重叠的机会)。

对于一个TextView多种风格看Is it possible to have multiple styles inside a TextView?

+0

是的,我试过不工作。 – 2010-02-16 10:05:16

+0

不起作用,也没有includeFontPadding – gregm 2011-03-02 13:16:01

6

我有完全相同的问题。我通过简单地在任何需要斜体的字符串末尾添加空格来解决这个问题。

它可能不是最长期正确的解决方案,但它对我有用。

+1

是的,这有效。使用一个额外的空间或使用“fill_parent”作为宽度。耻辱这不是由Android正确处理(我的是​​2.3.7)。 – shkschneider 2012-04-24 15:40:58

+1

如果您使用XML,则必须使用\ u0020来强制空格。 – 2013-01-04 21:50:39

1

您可以使用&#160;和string.xml文件中的文本。