Name University RelativeLayout ViewGroup .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#bdbdbd"
android:paddingBottom="15dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="15dp">
<ImageView
android:id="@+id/avatar"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerVertical="true"
android:src="@drawable/default_avatar" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_toEndOf="@id/avatar"
android:layout_toRightOf="@id/avatar">
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chris"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/university"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:text="Oxford"
android:textSize="13sp" />
</RelativeLayout>
</RelativeLayout>
This makes sense to group related views (TextViews), and also gives a better result, because the entire container is centered, in your original example. The name view is centered vertically, but another view is below it, and this makes it look not how much it will be in the case of the container, where the base level is the main center of the container.
source
share