Search code examples
androidlistviewtextviewgravity

TextView in custom adapter (ListView) gravity right not working for one line text


So I have custom adapter listView. There I have TextView. And I want to show it from right (gravity.right)

But when I am setting attribute Gravity.Right (I also tried change it dynamically) But it is not working for single line text and working for multiple line text. Like in this picture

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">


<TextView
    android:id="@+id/"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Acer"
    android:textColor="@color/"
    android:textSize="36sp"
    app:fontFamily="@font/" />

<TextView
    android:id="@+id/"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textColor="@color/"
    app:fontFamily="casual" />

<TextView
    android:id="@+id/"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:text="Lorem Ipsum is simply dummy text of"
    android:textColor="" />

enter image description here


Solution

  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="end"
        android:orientation="vertical"
        android:padding="15dp">
    
    
        <TextView
            android:id="@+id/"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textColor="@color/"
            android:textSize="36sp"
            app:fontFamily="@font/" />
    
        <TextView
            android:id="@+id/"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textColor="@color/"
            app:fontFamily="casual" />
    
        <TextView
            android:id="@+id/"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
    
            android:gravity="right"
            android:textColor="@color/" />
    
    </LinearLayout>