omega
omega

Reputation: 43873

How to combine textview and imageview into image compound when imageview has width and height values in android?

Hi have this in my XML file:

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/picture_text"
                android:layout_width="32dp" 
                android:layout_height="32dp"
                android:layout_marginRight="10dp"
                android:src="@drawable/text"/>

            <TextView 
               android:id="@+id/textview_message"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"               
               android:text="@string/tap_message"
               android:onClick="GoToMessage"                
               android:clickable="true"
               style="@style/text_link"/>
        </LinearLayout>

Android lint complains with a warning that this should be combined in a textview compound. I can do that, but I don't understand how to set the width, height, and margin for the imageview...

Can anyone show me how to do this?

Thanks

Upvotes: 0

Views: 2415

Answers (1)

Martin Cazares
Martin Cazares

Reputation: 13705

It's recommending to add a drawable within the textview as follows:

<TextView
     android:id="@+id/title"
     android:drawableLeft="@yourDrawable"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="yourText">
            </TextView>

Hope this helps.

Regards!

Upvotes: 1

Related Questions