Solve android:background background picture being stretched problem

Source: Internet
Author: User

The difference between the XML attribute src and background in ImageView:

The background is stretched according to the length and width given by the ImageView component, while SRC stores the size of the original and does not stretch. SRC is the picture content (foreground), BG is the background and can be used simultaneously.

In addition:ScaleType only works on SRC; BG can set transparency, such as the ability to use Android:scaletype to control how images are scaled in ImageButton

Solutions for reference

Toolbar_bg_selector.xml:

  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <item android:state_pressed="true" >
  4. <bitmap android:src="@drawable/toolbar_bg_sel" android:tilemode="Disabled " android:gravity="Top" />
  5. </Item>
  6. <item >
  7. <bitmap android:src="@drawable/toolbar_bg" android:tilemode="disabled" Android: gravity="Top" />
  8. </Item>
  9. </selector>

Resolve Android:background background picture is stretched

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.