enter image description here

enter image description here

File MainActivity.java:

package test; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private TextView mHelloTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mHelloTextView = (TextView)findViewById(R.id.textView); } public void onClick(View view) { mHelloTextView.setText("Clicked on"); } } 

Activity_main.xml file

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="test.MainActivity" android:clickable="false"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="52dp" android:src="@drawable/germany" android:onClick="onClick" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/greeting" android:id="@+id/textView" android:layout_below="@+id/imageButton" android:layout_alignRight="@+id/imageButton" android:layout_alignEnd="@+id/imageButton" android:layout_marginTop="55dp" /> </RelativeLayout> 

PS text Hello, i'm ikerya is in the same position as Clicked on .

PS PS Device: Lenovo A6010, 5 inches, Lollipop 5.0.2

  • Add more markup to the question. In general, relying on studio tools in the case of markup is not worth it - everything is bad because need a full-fledged device to account for all the nuances of a specific markup. - Yuriy SPb
  • @Yuriy SPb did - ikerya

1 answer 1

It's all about the length of the text and the width of the TextView and its alignment along the right edge of the overlying widget.

In the studio, your text is longer and it is not noticeable that its container on the right is bounded by the right edge of the overlying element.

Most likely, what you need can be done with android:layout_centerHorizontal="true" , which will replace layout_alignRight and layout_alignEnd :

 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/greeting" android:id="@+id/textView" android:layout_below="@+id/imageButton" android:layout_centerHorizontal="true" android:layout_marginTop="55dp" />