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/> </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------> How to use Android embedded image insetdrawable