Problem
I'm working on a UI library to android , where hedge the layout parameters ( height
, width
, weight
and gravity
) dynamically via code in a LinearLayout.LayoutParams
object but the gravity
attribute does not seem to have the same setGravity(gravity)
.
Note: I do not directly link to
View
because in component encoding I do not intend to have access toView
directly.
What I do briefly is something like this:
// width = 0, height = LinearLayout.LayoutParams.WRAP_CONTENT, weight = 1000
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,
LinearLayout.LayoutParams.WRAP_CONTENT, 1000);
params.gravity = Gravity.RIGHT;
textView1.setLayoutParams(params);
But View
does not align right as it should.
Now if I make the following code then it works:
// width = 0, height = LinearLayout.LayoutParams.WRAP_CONTENT, weight = 1000
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,
LinearLayout.LayoutParams.WRAP_CONTENT, 1000);
textView1.setLayoutParams(params);
textView1.setGravity(Gravity.RIGHT);
Question?
- Why does this happen?
-
textview1
of objectgravity
andLinearLayout.LayoutParams
ofsetGravity
are different attributes? - What's the difference between the two approaches? Is there any way to get the same result of
View
of setGravity
in View
of object gravity
?
Note: The
LinearLayout.LayoutParams
that I refer to in the question, in this case isView
.For clarity, I did a example in% with% of the effect I want on
TextView
of myHTML
android throughlayout
.