【问题标题】:Justify text alignment in Android在Android中对齐文本对齐
【发布时间】:2011-12-26 18:38:54
【问题描述】:

我目前正在从服务器的 xml 文件中将文本加载到我的应用程序中。 然而,这些文本被分配给 TextView。 我的文本没有按照我的需要对齐。即我希望这些文本作为 microsoft word 理由。

<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 文件应该做些什么?

【问题讨论】:

    标签: android user-interface textview alignment


    【解决方案1】:

    你可以试试:

     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 布局,我得到了以下输出:

    【讨论】:

    • 我已经尝试过了,因为你看到文本居中但不对齐到左或右。android:gravity="left |right|center |fill_horizo​​ntal" 如果你看到这里,我们使用 OR( |) 我们没有 AND 条件。
    猜你喜欢
    • 1970-01-01
    • 2015-08-23
    • 2020-07-12
    • 1970-01-01
    • 2015-02-12
    • 2020-05-23
    • 2017-02-17
    • 2017-06-02
    相关资源
    最近更新 更多