Android RelativeLayout align items

0

I can not align the items in the third line marked in the image vertically by the center. This is a layout of items in a listView.

I've tried gravity="center", layout_gravity="center", layout_centerVertical="true".

Would not you like to use a LinearLayout to group the items, any ideas?

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:padding="5dp">

    <TextView
        style="@style/textBase"
        android:id="@+id/labNom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nome da categoria"/>

    <TextView
        style="@style/textNote"
        android:id="@+id/labDes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/labNom"
        android:paddingTop="8dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:text="Descrição longa da categoria"/>

    <ImageView
        android:id="@+id/img1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/labDes"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_thumb_up"/>

    <TextView
        android:id="@+id/lab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/labDes"
        android:layout_toLeftOf="@+id/img1"
        android:text="57"/>

</RelativeLayout>
    
asked by anonymous 11.09.2016 / 23:28

1 answer

1

Set your ImageView and TextView within LinearLayout with gravity=center and everything is fine, this way:

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/labDes"
        android:layout_alignParentRight="true"
        android:gravity="center">

        <TextView
            android:id="@+id/lab1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"    
            android:layout_toLeftOf="@+id/img1"
            android:text="57"
            />
        <ImageView
            android:id="@+id/img1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/labDes"
            android:src="@drawable/ic_thumb_up"
            />
    </LinearLayout>

Good Luck!

    
12.09.2016 / 00:22