在Android中对齐文本对齐方式

时间:2011-11-11 06:01:53

标签: android user-interface textview alignment

我目前正在从服务器的xml文件中将文本加载到我的应用程序中。 但是,这些文本被分配给TextView。 根据我的需要,我的文字没有对齐。即我希望这些文字成为微软的词语理由。

<TextView android:id="@+id/nvContent"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="5dip"
      android:layout_marginTop="5dip"
      android:layout_weight="1"
      android:gravity="fill"
     android:text="Inglot Cosmetics now in Kathmandu Inglot, which has been selling its products in over 240 stores all over the world is now here for you in Kathmandu. It has one of the most extensive colour ranges in cosmetics collections. Working with the best makeup artists, Inglot brings you the latest trends in colour, texture and form. Experiment with countless shades and combinations of face powder, blushers, eye shadows and lipsticks."
    android:textColor="#ff000000"
    android:textSize="14sp" />

文字有点长。 我的应用程序不像textview那样显示文本对齐方式。 我希望这些文字合理。 这可能吗?我在stackoverflow.com上读到,Android不支持文本对齐,因为它是合理的。 任何替代品。或者我的xml文件应该做什么?

1 个答案:

答案 0 :(得分:8)

您可以尝试:

 android:gravity="center"

而不是

android:gravity="fill"

还可以通过android:padding提供一些填充。

最终解决方案:

 <TextView 
       android:id="@+id/nvContent"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_marginBottom="5dip"
       android:layout_marginTop="5dip"
       android:padding="10dp"
       android:gravity="center"
       android:text="Inglot Cosmetics now in Kathmandu Inglot, which has been selling its products in over 240 stores all over the world is now here for you in Kathmandu. It has one of the most extensive colour ranges in cosmetics collections. Working with the best makeup artists, Inglot brings you the latest trends in colour, texture and form. Experiment with countless shades and combinations of face powder, blushers, eye shadows and lipsticks."
       android:textColor="#ff000000"
       android:textSize="14sp" />

<强>输出: 我使用上面的XML布局得到了以下输出:

enter image description here