My Android advanced tour ------> Android embedded image InsetDrawable usage, androiddrawable
Interview question: Can I specify a background image for a LinearLayout layout filled with the entire Screen to make the background image not full of the screen? Use code to describe the implementation process.
To solve this problem, you can use an Inset image resource to specify an image, and then use an embedded image resource like a common image resource.
Syntax:
<?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 image to the top.
Android: insetRight: the distance from the image to the right.
Android: insetBottom: the distance from the image to the bottom edge.
Android: insetLeft: the distance from the image to the left.
The following example shows the specific effect.
First define an embedded image resource, 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" />
Android: drawable = "@ drawable/background" refers to the background.jpg file in the drawabledirectory. The image is as follows:
Use the inset. xml file directly 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 image --> <Button android: id = "@ + id/buttonRingtone" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "set ringtone"/> <Button android: id = "@ + id/buttonAlarm" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Set alert tone"/> <Button android: id = "@ + id/buttonNotification" android: layout_width = "wrap_content" android: layout_height = "Wrap_content" android: text = "set notification ringtones"/> <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 figure shows that the background image is not full:
========================================================== ========================================================== ============================
Author: Ouyang Peng: Welcome to repost. sharing with others is the source of progress!
Reprinted Please retain the original address: http://blog.csdn.net/ouyang_peng
========================================================== ========================================================== ============================
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.