Change
android:gravity="right"
to
android:gravity="left"
in the LinearLayout
with id passedlayout
Pergunta
Consider the xml file with the following textview layout:
I am trying to set the alignment of my this textview whose values are coming dynamically such that it should be:
One:24
Two:6000
The problem the layout is coming like this:
How to align it properly?
My xml is having visibility:gone set for One:
and Two:
text views. Then in my java file, I am doing like so:
one.setText("One:"+entries.get("one"));
two.setText("Two:"+entries.get("two"));
if(entries.get("type").equals("OneType"))
{
one.setVisibility(View.VISIBLE);
two.setVisibility(View.GONE);
}
else
{
one.setVisibility(View.VISIBLE);
two.setVisibility(View.VISIBLE);
}
UPDATE:
The xml file relevant code:
<LinearLayout
android:id="@+id/passedlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical"
>
<TextView
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:visibility="gone"
android:textColor="#000000"
android:textStyle="bold"/>
<TextView
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:visibility="gone"
android:textColor="#000000"
android:textStyle="bold"/>
</LinearLayout>
UPDATE:
I have multiple such rows for a single layout. Setting the gravity to left worked for the single layout. However for more than one rows having varying digits, the layout again gets disturbed like this-
Layout1:
One:24
Two:6000
Layout2:
One:0
Two:0
You see that One: and Two: of Layout1
are not aligned with One: and Two: of Layout2
.
Solução
Change
android:gravity="right"
to
android:gravity="left"
in the LinearLayout
with id passedlayout