Reputation: 860
this question may be asked earlier, but I really dont know how to search it also.
What I want to achieve is something like this.
city : some city
state : some state
pincode : some pin code
phone no : some phone number
the city : is one text view and some city is the second text view. both in linear layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="City : "
android:textSize="15sp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView android:text="Some city"
android:textSize="15sp"
android:id="@+id/lblPermanentCity"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</LinearLayout>
any help would be appreciate
Upvotes: 1
Views: 725
Reputation: 183
Why don't you table layout.I thinks it's best solution to your problem.
Upvotes: 1
Reputation: 8747
You could use three TextView
s per row, one for city, state, etc, one for the ":" and one for the "some city", etc. Then place them in a RelativeLayout
and align your colons(:) to the right edge of the largest TextView
(probably your "phone no").
Upvotes: 1
Reputation: 39039
I don't think you can pull this off with just two TextViews. The problem is that the title ("city") is left aligned and the colon is right aligned.
If you can live with left aligned colons, you can use the layout_weight
property to make the title column the same size on all lines, like so:
...
<TextView android:text="City:"
android:layout_height="wrap_content"
android:layout_width="0"
android:layout_weight="40"/>
<TextView android:text="some city"
android:layout_height="wrap_content"
android:layout_width="0"
android:layout_weight="60"/>
This will give the title column 40% of the width and the values column 60% of the width. Make sure your LinearView
's layout_width
is match_parent
If you really must have the colons in the middle, just add a third TextView for the colon, giving it a fixed width (wrap_content
with the same content is enough)
Upvotes: 0