What\'s wrong with my code, I\'m trying to display my TextView named \"invalid\"
, in different locations (left,right,center), but the gravity (left,right,center) w
You have given your TextView width wrap_content, and that is the problem, Check below code and replace it to your code.
<TextView
android:id="@+id/txtInvalid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/invalid"
android:gravity="center"
/>
set android:layout_width="fill_parent"
for textView1
You set this text view a width of "wrap_content" it means, what ever the text is, the view take the size of the text.
and in the LinearLayout
, the default gravity (used here) is 'center'
you should try this :
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent" <= change this
android:layout_height="wrap_content"
android:text="@string/invalid"
android:gravity="center" <= then this gravity will be taken into account
/>
Make sure you don't have something like that hanging around
app:layout_box="left|top"
99% of the time, not working properly
== not used properly
.
You are mistaking gravity
and layout_gravity
.
gravity
is the way the text will align itself in the TextView
. The TextView
being in wrap_content
this does nothing, as the TextView
is exactly the size of the text.
layout_gravity
is the way the TextView
will align itself in its parent, in your case in the vertical LinearLayout