My Android Step-by-step tour------> How to use Android embedded image insetdrawable

Source: Internet
Author: User

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

Solve the problem. You can use an embedded (Inset) image resource to specify an image and then use an 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: The distance from the left side of the image.


The following uses detailed examples to see the detailed effect

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 "/>
The android:drawable= "@drawable/background" refers to the Background.jpg file under the Drawable folder. Images such as the following are seen:


You can then use the Inset.xml file directly as a normal image resource, such as the following code:

<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 detailed to 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

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


My Android Step-by-step tour------&gt; How to use Android embedded image insetdrawable

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.