My Android advanced tour ------ & gt; Android embedded image InsetDrawable usage, androiddrawable

Source: Internet
Author: User

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.

Related Article

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.