Reputation:
I want to make layout like this:
The problem is with aligning TextViews: I want them both to be centered horizontally. The only solution I've got is to use nested LinearLayout inside root RelativeLayout. Ho do I center TextViews horizontally using only the root RelativeLayout, without nested LinearLayout?
Upvotes: 2
Views: 282
Reputation: 22066
PLEASE TRY THIS ::
Update :
<?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:id="@+id/asdww"
android:background="#000000">
<TextView android:layout_width="wrap_content" android:id="@+id/textView1"
android:layout_height="wrap_content" android:text="TextView"
android:layout_centerHorizontal="true" android:layout_marginTop="60dp" />
<TextView android:layout_width="wrap_content" android:id="@+id/textView2"
android:layout_height="wrap_content" android:text="new aaaaaa"
android:layout_alignParentLeft="true" android:layout_centerHorizontal="true"
android:layout_marginTop="60dp" android:layout_below="@+id/textView1"
android:layout_marginLeft="50dp"
/>
<TextView android:layout_width="wrap_content" android:id="@+id/textView3"
android:layout_height="wrap_content" android:text="new aaaaaa"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true" android:layout_marginTop="60dp"
android:layout_below="@+id/textView1"
android:layout_marginRight="50dp"
/>
</RelativeLayout>
Upvotes: 1
Reputation: 6728
Lets say the id 0f imageview
is image. Then for the 1st textView
you can do something like this :
android:layout_alignLeft="@id/image"
and for the 2nd textView
,
android:layout_alignRight="@id/image"
You can also give some margin in both the textViews
after doing this
Upvotes: 4
Reputation: 599
In your LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
The textviews shall be centered yourself thats of my knowledge. You can implement android:layout_marginLeft
Upvotes: 1