My Android Step-by-step tour------>android embed image insetdrawable usage

Source: Internet
Author: User

Interview question: Is it possible to make the background map not fill the screen by specifying a background map for a linearlayout layout that fills the entire screen? Please describe the implementation process in code.

To resolve this problem, you can use an embedded (Inset) image resource to specify the image and then use the embedded image resource as you would with a normal image resource.

The syntax is as follows:

<?XML version="1.0"encoding="Utf-8"?><Inset    xmlns:android="Http://schemas.android.com/apk/res/android"    android:drawable="@drawable/Drawable_resource"    Android:insettop="Dimension"    Android:insetright="Dimension"    Android:insetbottom="Dimension"    Android:insetleft="Dimension" />
element Explanation:

Android:insettop: The distance from the top of the image.

Android:insetright: The distance from the right side of the image.

Android:insetbottom: The distance from the bottom edge of the image.

Android:insetleft: Distance from the left of the image.


Here's a concrete example of how this works

First , an embedded image resource is defined, Res/drawable/inset.xml

<?xml version= "1.0" encoding= "Utf-8"?> <inset  xmlns:android= "http://schemas.android.com/apk/res/ Android "     android:drawable=" @drawable/background "     android:insetbottom=" 50DP "     android:insetleft=" 50DP "     android:insetright=" 50DP "     android:insettop=" 50DP "/>
where android:drawable= "@drawable/background" refers to the Background.jpg file under the drawable directory, the image is as follows:


Then directly use the Inset.xml file as a normal image resource, the code is as follows:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" android:background= "@drawable/inset" >< !--use Inset.xml as the background--<button android:id= "@+id/buttonringtone" android:layout_width= "Wrap_conten T "android:layout_height=" wrap_content "android:text=" Set call ringtone "/> <button android:id=" @+id/bu Ttonalarm "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:text=" Set the alarm Bell ringtones "/> <button android:id=" @+id/buttonnotification "android:layout_width=" Wrap_content "and        roid:layout_height= "Wrap_content" android:text= "set notification ringtone"/> <edittext android:id= "@+id/text"        Android:layout_width= "Match_parent" android:layout_height= "Wrap_content" > <!--the current control is in focus state-- <requestfocus/> &LT;/edittext></linearlayout> 

the following is specific and you can see that the background graph does not occupy full screen:



==================================================================================================

Ouyangpeng welcome reprint, sharing with people is the source of progress!

Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng

==================================================================================================   



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

My Android Step-by-step tour------>android embed image insetdrawable usage

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.