I have expected that TextView was aligned to the right because of NO_GRAVITY
, however it was aligned to the left. Shouldn't NO_GRAVITY
leave the gravity setting as it is, instead of aligning it to the left. If I also remove this two lines belove, it still aligns the TextView to the left even if I specify android:layout_gravity="center" in xml code.
params.gravity = Gravity.RIGHT;
params.gravity = Gravity.NO_GRAVITY;
How can I change other properties of the layout without effecting its gravity? What is exactly the difference between LEFT
and NO_GRAVITY
?
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
params.gravity = Gravity.NO_GRAVITY;
textView.setLayoutParams(params);