java - Android - Center View in Other View inside Layout -


hi having trouble centering text view in image view. want kinda have vertically centered , stay vertically centered if the font size changes.

enter image description here

and here have in xml don't care if need change relative layout kind doesn't matter me want able center this. heres xml:

<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:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.spencer.app.profileactivity" android:id="@+id/layout">  <imageview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:minheight="140dp"     android:minwidth="140dp"     android:id="@+id/logobackground"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_marginleft="25dp"     android:layout_marginstart="25dp"     android:layout_margintop="25dp"     android:contentdescription="@string/content_description_useless"     android:background="#ffffd0cd" />  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@string/capital_u"     android:id="@+id/u_textview"     android:textsize="80sp"     android:layout_marginleft="31dp"     android:layout_marginstart="31dp"     android:layout_margintop="20dp"     android:layout_marginbottom="20dp"     android:layout_aligntop="@+id/logobackground"     android:layout_alignleft="@+id/logobackground"     android:layout_alignstart="@+id/logobackground" />  </relativelayout> 

thanks in advance.

try this

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/layout"     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="com.spencer.app.profileactivity" >      <imageview         android:id="@+id/logobackground"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true"         android:layout_alignparenttop="true"         android:layout_marginleft="25dp"         android:layout_marginstart="25dp"         android:layout_margintop="25dp"         android:background="#ffffd0cd"         android:contentdescription="@string/content_description_useless"         android:minheight="140dp"         android:minwidth="140dp" />      <textview         android:id="@+id/u_textview"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignbottom="@+id/logobackground"         android:layout_alignleft="@+id/logobackground"         android:layout_alignright="@+id/logobackground"         android:layout_alignstart="@+id/logobackground"         android:layout_aligntop="@+id/logobackground"         android:text="@string/capital_u"         android:textsize="80sp"         android:gravity="center" />  </relativelayout> 

Comments

Popular posts from this blog

c# - MSAA finds controls UI Automation doesn't -

python - mat is not a numerical tuple : openCV error -

wordpress - .htaccess: RewriteRule: bad flag delimiters -