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/> </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