Android : How to fix TextView move far left and right when rotated?

on Saturday, April 18, 2015


I want to make TextView align to left and right edges of window screen. The expect result will look like this


expected result


but the actual result look like this


actual result


Here is my XML...



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cameraContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/cameraPreview"
android:layout_width="match_parent"
android:layout_height="match_parent" />


<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@color/grey_700"
android:text="TEST TEXT TEST TEXT"
android:textColor="@color/white"
android:textSize="35sp" />

<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@color/grey_700"
android:text="TEST TEXT TEST TEXT"
android:textColor="@color/white"
android:textSize="35sp"
/>


<TextView
android:id="@+id/text3"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_700"
android:rotation="270"
android:text="TEST TEXT TEST TEXT"
android:textColor="@color/white"
android:textSize="35sp"
android:layout_alignBottom="@+id/text4"
android:layout_alignParentStart="true"
/>

<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grey_700"
android:rotation="90"
android:text="TEST TEXT TEST TEXT"
android:textColor="@color/white"
android:textSize="35sp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>


It seem like that when I rotate the textview, only the textview I rotated will move far left and far right.


Do you have any ideas how to make 2 text view on the left and right align as expect result?


Thank you!


0 comments:

Post a Comment