Reputation: 8945
Been trying to do this for a while, and nothing is working.
I'm trying to vertical and horizontal center a linear layout inside a relative layout.
The point is to get two text-views perfectly centered inside the relative layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textColor="#ff0fff"
android:background="#ffffff"
android:textSize="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textColor="#ff0fff"
android:background="#ffffff"
android:textSize="20dp"
/>
</LinearLayout>
</RelativeLayout>
Any help is appreciated.
Upvotes: 2
Views: 3553
Reputation: 3906
set attribute centerInParent
to true to center Linear Layout in Relative Layout and gravity
to center TextView in your LinearLayout
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center">
Upvotes: 8