How to center align 2 views?
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/viewPost"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="14dp"
android:background="@color/bg_blue"
android:gravity="center" >
<ImageView
android:id="@+id/ic_viewPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_view" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/ic_viewPost"
android:gravity="center"
android:text="View post"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/socialShare"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="14dp"
android:background="@color/bg_light_grey"
android:gravity="center" >
<ImageView
android:id="@+id/ic_socialShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_share_post" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/ic_socialShare"
android:gravity="center"
android:text="Share with others"
android:textColor="@color/text_dark_grey"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
In graphical layout:
On actual device:
In the graphical layout it looks the way I wanted, but on actual device
its completely different.
In the 1st Relative Layout the ImageView and TextView are not at all aligned.
In the 2nd Relative Layout it looks like the TextView is bottom aligned to
the ImageView.
Thank You.
No comments:
Post a Comment