Issue
I'm currently working on an app to display two text views at opposite ends of the screen.
This does work on some devices but on others it creates a new line and messes things up entirely or just removes the 22 entirely like this:
This is the xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start">
<TextView
android:textSize="13sp"
android:textColor="@color/black"
android:gravity="start"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="James Lingard" />
<TextView
android:textSize="13sp"
android:textColor="@color/black"
android:gravity="start"
android:layout_marginStart="410dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22" />
</RelativeLayout>
The name on the left is great but the number on the right keeps getting messed up. I assume it has something to with android:layout_marginStart="410dp"
but I'm not sure how else I can get the 22 to be on the right and on the same line as the name.
Solution
Try this, with RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="13sp"
android:textColor="@color/black"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="James Lingard" />
<TextView
android:textSize="13sp"
android:textColor="@color/black"
android:gravity="start"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22" />
or I recomanded(is most adaptable) (P.S. Sorry for my english)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="13sp"
android:textColor="@color/black"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="James Lingard" />
<TextView
android:textSize="13sp"
android:textColor="@color/black"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="22" />
Answered By - Tudor Deviza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.