Android implements ImageView compression and solves the problem of applying for background images,

Source: Internet
Author: User

Android implements ImageView compression and solves the problem of applying for background images,

Create a. XML file named: image_tab_bg.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <selector3 xmlns: android = "http://schemas.android.com/apk/res/android"> 4 <item android: state_pressed = "true" android: drawable = "@ drawable/image_press"/> // press chip 5 <item android: state_enabled = "true" android: drawable = "@ drawable/image"/> // picture 6 not pressed </selector>

Then set the src of the image ImageView to @ drawable/image_tab_bg.

Note: Do not set it to the Background attribute of ImageView. In this way, the image will be rejected.

 

Differences between the XML Attribute src and background in ImageView:

Background is stretched Based on the length and width specified by the ImageView component, while src stores the source image size and does not stretch. Src is the image content (foreground), bg is the background, and can be used at the same time.

In addition, scaleType only applies to src; bg can set transparency. For example, android: scaleType can be used in ImageButton to control the image scaling mode.

 

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.