Is it possible to align the text "1 minute ago" in RelativeLayout relative to the "Share" button so that the text "1 minute ago" is always in the middle of the button, and not at the top, as it is now.

enter image description here

`

  <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="15dp"> <TextView android:id="@+id/one_news_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1 минуту назад" android:textSize="12sp" android:textColor="@color/weak_gray" android:layout_alignBottom="@+id/one_news_likes_text" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <ImageView android:id="@+id/one_news_likes_pic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/ic_menu_gallery" android:layout_marginLeft="28dp" android:layout_marginStart="28dp" android:layout_centerVertical="true" android:layout_toRightOf="@+id/one_news_share_button" android:layout_toEndOf="@+id/one_news_share_button" /> <TextView android:id="@+id/one_news_likes_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="лойс" android:textColor="@color/grey" android:layout_centerVertical="true" android:layout_toRightOf="@+id/one_news_likes_pic" android:layout_toEndOf="@+id/one_news_likes_pic" /> <Button android:id="@+id/one_news_share_button" android:layout_width="125dp" android:layout_height="25dp" android:text="Поделиться" android:textAllCaps="false" android:textSize="12sp" android:drawableLeft="@android:drawable/ic_menu_gallery" android:background="@drawable/button_style_background" android:layout_gravity="center_horizontal" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> </RelativeLayout>` 
  • You already have it: android: layout_centerVertical = "true" - xAqweRx
  • did not know about him. thank! - Paranoid Android

1 answer 1

To align vertically in RelativeLayout:

 android:layout_centerVertical="true" 

To align horizontally in RelativeLayout:

 android:layout_centerHorizontal="true"