Set the background image tile in Android.

Source: Internet
Author: User

Note: This article is written by Colin, all rights Reserved! Reprint please specify the original address, thank you for your cooperation!

In the development of Android, we often need to set a background for the program, but because of the size of the current Android device, if you arbitrarily set a picture as the background, it is likely to be stretched on different devices, the user's visual experience will be poor, then how to solve this problem, Here's a rookie here to share the experience.

First, the need to define an XML file in the drawable-mdpi directory, where I named bitmap

Write the following code, specified in SRC as the name of the picture you want to tile:

<?xml version= "1.0" encoding= "Utf-8"? ><bitmap xmlns:android= "Http://schemas.android.com/apk/res/android" android:src= "@drawable/img01" android:id= "@+id/app_bg" android:tilemode= "repeat"/>

Second, in the layout configuration master file will be set the most external frame background to bitmap, as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><scrollview xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:id=" @+id/content "Android: background= "@drawable/bitmap" ><textview android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "android:text=" @string/hello_world "/></scrollview>

  

At this point, run the virtual machine and see how it works.

Implementation effects such as (without the rounded rectangles and translucent effects in the diagram, the implementation of rounded rectangles see the next article):

Demo: Download Android rounded rectangle and semi-transparent demo

Set the background image tile in Android.

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.