Android - How to align an image center relative to the textview

I have an text view as show above and an info icon next to the text view. All is fine here but I wish to have the info icon aligned center to the textview. As of now it is aligned top right relative to the text view. I wish it to be aligned center right relative to the text view

The XML Layout file is below

        <RelativeLayout
             android:orientation="horizontal" 
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
              android:gravity="center"
            android:layout_gravity="center"
            > 

        <TextView               
            android:id="@+id/ViewMessageOne"                
            android:layout_width="275dp"
            android:layout_height="45dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000"
            android:textSize="14sp"
            android:typeface="sans" 
            android:background="@drawable/back"
            />   

         <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/banner_portrait"
            android:layout_toRightOf="@+id/ViewMessageOne"
            android:paddingLeft="10dp"
             android:gravity="center"               
           />


         </RelativeLayout>

Please point me in the right direction. Thanks for your help

Answers


Try:

android:layout_gravity="center_vertical|right"

EDIT:

You could also just change the height to match the TextView, as your ImageView gravity is set to center.

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:layout_toRightOf="@+id/ViewMessageOne"
    android:gravity="center"
    android:paddingLeft="10dp"
    android:src="@drawable/banner_portrait" />

Unless you have a specific need for the ImageView, you could take that out and use drawableRigh on your TextView

<TextView               
        android:id="@+id/ViewMessageOne"                
        android:layout_width="275dp"
        android:layout_height="45dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000"
        android:textSize="14sp"
        android:typeface="sans" 
        android:background="@drawable/back"
        android:drawableRight="@drawable/banner_portrait"   // here
        />   

Need Your Help

Saving MYSQL CSV to the server

php mysql output

I have some code which i am trying to use to generate a CSV file from MYSQL and then save it to the server. The folder the file is trying to save to has the write property set. however when i run ...

ClassCastException: AdView mistakenly get casted to an EditText

java android admob android-edittext classcastexception

&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"