TextView文本打印本身

时间:2012-11-12 06:58:03

标签: android

我目前有一个标准的文字视图

<TextView
    android:id="@+id/tvTaskDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tvTaskName"
    android:text="Date"
    android:layout_marginRight="30dp"
    android:paddingLeft="30dp"
    android:textAppearance="?android:attr/textAppearanceLarge" />

我正在以编程方式设置视图的字体,文本大小和文本。

font = Typeface.createFromAsset(getAssets(), "fonts/Helvetica LT 75 Bold.ttf");
TextView tv = (TextView)(findViewById(R.id.tvTaskDate));
tv.setTypeface(font);
tv.setTextSize(20.0f);
tv.setText(getIntent().getExtras().getString("name"));

问题在于它是这样出现的:

enter image description here

如果我注释掉设置字体的行,则textView会向下移动到下一行,并按照它的方式处理文本。我尝试设置MaxLine()属性,但它仍然以相同的方式运行。

设置textView的字体时是否必须设置其他属性?

1 个答案:

答案 0 :(得分:0)

基于Lokesh上面的评论,使用

tv.setLineSpacing(21.0f, 1);

解决了这个问题。由于我使用的是除了textviews标准之外的新字体,因此我必须定义这些行之间的间距。

相关问题