If you use LinearLayout then you will find two gravity attributeĪndroid:gravity : represent layout potion of internal text of TextView whileĪndroid:layout_gravity : represent TextView position in parent view. TextView gravity works as per your parent layout. The TextView's height and width are wrap content then the text within the textview always be centered, then make center in its parent layout by using: įor LinearLayout also the code is same : Īnd pro-grammatically parent is RelativeLayout java code this at run time use something like this in your activity TextView textView1 =(TextView)findViewById(R.id.texView1) Java method 03 tTextAlignment(View.TEXT_ALIGNMENT_CENTER) Java method 01 tGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL) We can achieve this with these multiple ways:. LayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE) RelativeLayout.LayoutParams layoutParams = RelativeLayout.LayoutParams)textView1.getLayoutParams() tGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL) įor Relative Layout: in XML use some thing like this To do this at run time use something like this in your activity TextView textView1 =(TextView)findViewById(R.id.texView1)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |