代码之家  ›  专栏  ›  技术社区  ›  Shubham Sejpal Andy

在textview中,ellipsize=“end”和gravity=“center”工作不正常

  •  0
  • Shubham Sejpal Andy  · 技术社区  · 8 年前

    我需要这样的文本视图,带有maxline=“2”

    enter image description here

    enter image description here


    当我给它 重力=“中心垂直” ellipsesize=“结束” 它会给我比上面一个更好,但我需要在中心的问候文字好看。

    enter image description here


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
    
                <TextView
                    android:id="@+id/tv_list_music_songname"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:ellipsize="end"
                    android:maxLines="2"
                    android:gravity="center"
                    android:includeFontPadding="false"
                    android:padding="5dp"
                    android:text="Hello ABCDEFGHIJKLMNOPQRSTUVW"
                    android:textSize="15dp" />
    
                <TextView
                    android:id="@+id/tv_list_music_songtimeduration"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:padding="5dp"
                    android:text="ABC"
                    android:textSize="15dp" />
            </LinearLayout>
    
    3 回复  |  直到 8 年前
        1
  •  1
  •   Amrutha Saj    8 年前

    尝试以下操作

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    
        <TextView
            android:id="@+id/tv_list_music_songname"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:maxLines="2"
            android:gravity="center"
            android:includeFontPadding="false"
            android:padding="5dp"
            android:text="Hello \n ABCDEFGHIJKhhLMNOPQRSTUVW"
            android:textSize="15dp" />
    
        <TextView
            android:id="@+id/tv_list_music_songtimeduration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
    
            android:gravity="right"
            android:padding="5dp"
            android:text="ABC"
            android:textSize="15dp" />
    </LinearLayout>
    
        2
  •  1
  •   Hasmukh Kachhatiya    8 年前

    试着这样做

      <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:weightSum="2"
                  android:orientation="horizontal">
    
                <TextView
                    android:id="@+id/tv_list_music_songname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.6"
                    android:ellipsize="end"
                    android:maxLines="2"
                    android:gravity="center"
                    android:includeFontPadding="false"
                    android:padding="5dp"
                    android:text="Hello \n ABCDEFGHIJKLMNOPQRSTUVW"
                    android:textSize="15dp" />
    
                <TextView
                    android:id="@+id/tv_list_music_songtimeduration"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.4"
                    android:gravity="right"
                    android:padding="5dp"
                    android:text="ABC"
                    android:textSize="15dp" />
          </LinearLayout>
    
        3
  •  -2
  •   Gowthaman M manas.abrol    8 年前

    "center_vertical|center_horizontal" 尝试以下代码

    android:gravity="center_vertical|center_horizontal"