Android ImageButton does not display text when the Drawable image is displayed

Source: Internet
Author: User

Many people have questions about ImageButton provided by Android. When a Drawable image is displayed, text is no longer displayed. There are three solutions:

First:That is, text is written into the image, but this will increase the size of the program, and the hard encoding method will affect the publishing of multi-language languages.
Second:The solution is very simple. Through analysis, we can see the layout of ImageButton. We can directly inherit the layout by adding a TextView and alignment to the right side to enable ImageButton to support displaying the right side of the text.
Third:More concise and efficient method: Use the Button and set the android: drawableLeft and other attributes of the Button. Example:Copy codeThe Code is as follows: <Button
Android: id = "@ + id/button1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: drawableLeft = "@ drawable/icon"
Android: text = "button"
/>

Fourth:Multiple layers with LayoutCopy codeThe Code is as follows: <LinearLayout
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: orientation = "vertical"
Android: id = "@ + id/bt">
<ImageView
Android: id = "@ + id/ib"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/ringlove"
Android: background = "#00000000"
/>
<TextView
Android: id = "@ + id/TV"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/cs"
Android: paddingLeft = "20px"
/>
</LinearLayout>

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.