Android achieves text and image mixing,

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.