【问题标题】:Justified Text with central alignment in android在android中具有中心对齐的对齐文本
【发布时间】:2015-08-23 21:53:14
【问题描述】:

大家好,我正在开发 android 应用程序,我正在使用 TextView 显示一些文本,并在屏幕上居中对齐。但问题是文本在屏幕上没有正确对齐。这是我用来在屏幕上显示居中对齐的文本的 xml 代码。请帮我做这件事。

<TextView
        android:id="@+id/lastMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_gravity="center"
        android:text="Mana addd asdwd ekff fec greq crrq grooe cieurnf covhrpw cjcneie ejducbc ueiche deidhe idhcecm ekwp ww"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="12sp" />

【问题讨论】:

    标签: android textview center


    【解决方案1】:

    此库将为您提供一种对齐文本的方法。

    兼容 Android 2.2 到 5.X

    https://github.com/bluejamesbond/TextJustify-Android

    【讨论】:

      【解决方案2】:

      尝试android:layout_centerInParent="true"android:layout_centerHorizontal="true" 这些适用于RelativeLayout

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="@color/white">
      
           <TextView
              android:id="@+id/lastMessage"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="20dp"
              android:paddingLeft="10dp"
              android:paddingRight="10dp"
              android:layout_centerHorizontal="true"
              android:layout_gravity="center"
              android:text="Mana addd asdwd ekff fec greq crrq grooe cieurnf covhrpw cjcneie ejducbc ueiche deidhe idhcecm ekwp ww"
              android:textAppearance="?android:attr/textAppearanceSmall"
              android:textSize="12sp" />
      
      </RelativeLayout>
      

      并关注this answer 为它辩护。

      【讨论】:

        【解决方案3】:

        如果要居中对齐文本,请使用android:gravity="center",如下所示:

        <TextView
            android:id="@+id/lastMessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Mana addd asdwd ekff fec greq crrq grooe cieurnf covhrpw cjcneie ejducbc ueiche deidhe idhcecm ekwp ww"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="12sp" />
        

        【讨论】:

          猜你喜欢
          • 2011-12-26
          • 1970-01-01
          • 2011-11-11
          • 2020-04-14
          • 2012-11-11
          • 1970-01-01
          • 2015-09-04
          • 2019-09-02
          • 1970-01-01
          相关资源
          最近更新 更多