Reputation:
I want to align many textviews (Contained in each listView item) as alignParentLeft
, in CSS we use float:left
and the elements should be blocks (in CSS), here's my xml layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="5dp"
android:paddingBottom="5dp" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:textColor="#000" />
<TextView
android:id="@+id/ticketsCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#000"
android:background="#fff"
android:textStyle="bold"
android:padding="3dp" />
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dp"
android:textStyle="bold"
android:textColor="#000" />
<TextView
android:id="@+id/CityCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dp"
android:textColor="#000" />
<TextView
android:id="@+id/StartingDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dp"
android:textColor="#000" />
<TextView
android:id="@+id/EndingDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dp"
android:textColor="#000" />
<TextView
android:id="@+id/ticketCategories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="25dp"
android:textColor="#000" />
</RelativeLayout>
the 2 first textviews are well positionned but the others are NOT.
How can I do this ? Thank you.
EDIT : this is what I get actually :
Upvotes: 3
Views: 2600
Reputation: 5162
You are not getting this problem because your textview are not aligned to the left - you are getting this problem because you have given all your textview the same attribute - android:layout_marginTop="25dp"
which means that they will all be the same distance from the top.
To fix this you need to make your textview relative to each other - for example, you CityCountry
text view should have the attribute android:layout_below="@id/address"
That is how a RelativeLayout
works, because it lets you put elements on top of each other, you have to specify when you don't want them to be on top of each other.
Alternatively you could use a LinearLayout
with the attribute android:layout_gravity="right"
and this would stop the textviews from overlapping.
Upvotes: 1