0

I was trying to show some data fetched from the JSON in android TextView. It was all going great but the last tip of the data fetched was cut. If you see closely to the image, the "y" in Lakshay is slighly cut along with 16(i.e age) .I checked every margin, tried doing padding at the end and also checked some other answers, but I was not able to solve it. So here is my XML code and a screenshot of the problem.Click here for the image

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp"
    tools:context="com.lakshay.loginregister.UserData">
    <TextView
        android:id="@+id/name_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name :- "
        android:textColor="#000"
        android:textSize="25sp"
        android:textStyle="bold|italic" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/name_tv"
        android:paddingStart="5dp"
        android:text="Abc"
        android:paddingEnd="10dp"
        android:gravity="fill"
        android:textColor="#cc2222"
        android:textSize="25sp"
        android:id="@+id/name"
        android:layout_alignBaseline="@+id/name_tv"
        android:textStyle="bold|italic" />

    <TextView
        android:id="@+id/surname_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Surname :- "
        android:textColor="#000"
        android:textSize="25sp"
        android:layout_below="@id/name_tv"
        android:paddingTop="10dp"
        android:textStyle="bold|italic" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/surname"
        android:textColor="#cc2222"
        android:text="Surname"
        android:textSize="25sp"
        android:textStyle="bold|italic"
        android:layout_alignBaseline="@+id/surname_tv"
        android:layout_toEndOf="@id/surname_tv"
        android:paddingStart="5dp"/>

    <TextView
        android:id="@+id/age_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Age :- "
        android:textColor="#000"
        android:textSize="25sp"
        android:layout_below="@id/surname_tv"
        android:paddingTop="10dp"
        android:textStyle="bold|italic" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/age"
        android:textColor="#cc2222"
        android:text="Age"
        android:textSize="25sp"
        android:textStyle="bold|italic"
        android:layout_alignBaseline="@+id/age_tv"
        android:layout_toEndOf="@id/age_tv"
        android:paddingStart="5dp"/>

    <TextView
        android:id="@+id/username_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="UserName :- "
        android:textColor="#000"
        android:textSize="25sp"
        android:layout_below="@id/age_tv"
        android:paddingTop="10dp"
        android:textStyle="bold|italic" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/username"
        android:textColor="#cc2222"
        android:text="Username"
        android:textSize="25sp"
        android:textStyle="bold|italic"
        android:layout_alignBaseline="@+id/username_tv"
        android:layout_toEndOf="@id/username_tv"
        android:paddingStart="5dp"/>

</RelativeLayout>

Thanks for help.

L.Goyal
  • 773
  • 2
  • 6
  • 23
  • Are you doing this on any particular device? I checked this XML markup and it seems to be fine. The default text that you have added appears correctly – JGPhilip Mar 15 '18 at 06:21
  • I tried it on all devices but the output is the same. – L.Goyal Mar 15 '18 at 08:03
  • Other people are having the same issue here: https://stackoverflow.com/questions/4353836/italic-textview-with-wrap-contents-seems-to-clip-the-text-at-right-edge – Mathias Kirkegaard Mar 15 '18 at 09:54

2 Answers2

0

Please remove padding from your xml

     <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@id/name_tv"
    android:text="Abc"
    android:gravity="fill"
    android:textColor="#cc2222"
    android:textSize="25sp"
    android:id="@+id/name"
    android:layout_alignBaseline="@+id/name_tv"
    android:textStyle="bold|italic" />
0

Try to add an extra space after your every string which is cutting by adding \u0020 to the end of every string.

Yesha Shah
  • 408
  • 1
  • 5
  • 17
  • 1
    But why is it happening. Can anyone tell that – L.Goyal Mar 15 '18 at 12:11
  • 2
    android:layout_width="wrap_content" provides a rectangle for wrapped content rendering. It will work properly for normal text. As you are using italic text, the wrapped text will try to fit into the rectangle and the charachter which is at the right is getting cut off. @L.Goyal – Yesha Shah Mar 15 '18 at 13:29
  • If the answer helped you , you can accept the answer :) @L.Goyal – Yesha Shah Mar 19 '18 at 05:39