java - Android - Center Textview in ImageView of Relative Layout -
i have relative layout imageview in , want center textview in side imageview, in activity layout xml file.
here image view , have tried textview
this inside of relative layout:
<imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:minheight="170dp" android:minwidth="170dp" android:id="@+id/logobackground" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_marginleft="33dp" android:layout_marginstart="33dp" android:layout_margintop="33dp" 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/textview" android:textsize="30sp" android:layout_aligntop="@+id/logobackground" android:layout_alignleft="@+id/logobackground" android:layout_alignstart="@+id/logobackground" android:layout_marginleft="43dp" android:layout_marginstart="43dp" android:layout_margintop="65dp"/>
it looks okay think margintop 65 shouldn't half of height of imageview?
thanks in advance.
it's not working because you're telling textview in center of parent relativelayout, imageview attached top-left of parent.
one approach force textview exact size of imageview using relativelayout's alignxyz properties. set gravity attribute center, , makes text appear in center of textview's bounds. should work long imageview larger textview in dimensions.
<textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/capital_u" android:id="@+id/textview" android:textsize="30sp" android:layout_aligntop="@+id/logobackground" android:layout_alignleft="@+id/logobackground" android:layout_alignright="@+id/logobackground" android:layout_alignbottom="@+id/logobackground" android:gravity="center"/>
will work you?
Comments
Post a Comment