Android implements text-to-image blending

Source: Internet
Author: User

In our projects, we often encounter the problem of mixed images and text. There are many ways to solve this kind of problem, the method given in this paper is not unique, only according to the actual situation can find a more suitable method.

This article mainly through the XML layout to realize the picture and the text mix (arranges horizontally).


1. Use TextView to achieve picture and text mix,

Android:drawablebottom output a drawable, slice below the text.

If a color is specified, the background of text is set to that color, and the latter is overridden when used with background.
android:drawableleft on the left side of the text output a drawable, slice.
android:drawablepadding sets the interval between text and drawable (picture),

Used with Drawableleft, Drawableright, Drawabletop, Drawablebottom, can be set to negative numbers, use alone no effect.
Android:drawableright output a drawable to the right of text.
The android:drawabletop outputs a drawable directly above 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"/>

Among them, the Android:drawablepaddingh very good solves the picture and the text spacing question.

2. Add TextView and ImageView (Buttonview) using Relativelayout (linearlayout) to achieve

   <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 picture and text mix.

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.