Android achieves text and image mixing,
In our projects, image and text are often mixed. There are many ways to solve this type of problem. The method given in this article is not the only one. Only a more suitable method can be found based on the actual scenario.
This article mainly uses xml layout to achieve the mixing of pictures and text (horizontal arrangement ).
1. Use TextView to mix images and text,
Android: drawableBottom outputs a drawable under text.
If a color is specified, the background of the text is set to this color, and the latter is overwritten with the background.
Android: drawableLeft outputs a drawable on the left of text.
Android: drawablePadding sets the interval between text and drawable (image,
It can be used with drawableLeft, drawableRight, drawableTop, and drawableBottom. It can be set to a negative number, but it is ineffective to use it independently.
Android: drawableRight outputs a drawable on the Right of text.
Android: drawableTop outputs a drawable on the top of the text.
<TextView android: id = "@ + id/my_ TV" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "online" android: textColor = "# 85898f" android: layout_marginTop = "5dp" android: drawablePadding = "5dp" android: drawableLeft = "@ drawable/user_online"/>
Android: drawablePaddingh solves the issue of spacing between images and texts.
2. Use RelativeLayout (LinearLayout) to add TextView and ImageView (ButtonView ).
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/my_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/user_online" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="5dp" /> <TextView android:id="@+id/my_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/my_iv" android:layout_centerVertical="true" android:layout_marginLeft="5dp" /> </RelativeLayout>
In fact, you can also use java code to achieve mixed sorting of images and text.