Android drawable resource learning (8), insetdrawable

Source: Internet
Author: User

Insetdrawable indicates that a drawable is embedded into another drawable, and some padding is left inside it. This is similar to the padding attribute of drawable. The difference is that padding indicates the margin between drawable content and drawable, insetdrawable indicates the margin between two drawable and container. When the background required by the control is smaller than the actual border, insetdrawable is more suitable.

File Location:
res/drawable/filename.xml
The file name is the resource ID.
Compilation Resource Type:

Point to insetdrawablePointer

Resource reference:
In Java: R.drawable.filename
In XML: @[package:]drawable/filename
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
<inset>
Define this drawable as insetdrawable and must be used as the root node.

Attribute:

xmlns:android
StringType. Required. The namespace that defines the XML file must be "http://schemas.android.com/apk/res/android".
android:drawable
Drawable Resource. Required. Reference A drawable Resource
android:insetTop
Size. The distance from the top. You can set a dimension value or a dimension resource.
android:insetRight
Size. The distance from the right side. You can set a dimension value or a dimension resource.
android:insetBottom
Size. The distance from the bottom. You can set a dimension value or a dimension resource.
android:insetLeft
Size. The distance from the left. You can set a dimension value or a dimension resource.
Example:
<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android"    android:drawable="@drawable/background"    android:insetTop="10dp"    android:insetLeft="10dp" />
Refer:
  • InsetDrawable

Instance:

1. Define in XML file

Inset. xml:

<?xml version="1.0" encoding="utf-8"?><inset xmlns:android="http://schemas.android.com/apk/res/android"     android:drawable="@drawable/image4"    android:insetLeft="50dp"    android:insetRight="50dp"    android:insetTop="20dp"    android:insetBottom="20dp"></inset>

Used in layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"      android:background="@drawable/inset" >     <Button        android:id="@+id/btn"         android:layout_width="wrap_content"        android:layout_height="wrap_content"/></LinearLayout>

We can see that there is a gap between it and the boundary. It is defined in inset. xml.

2. Java code definition:

Simple:

//new InsetDrawable(drawable, insetLeft, insetTop, insetRight, insetBottom) InsetDrawable insetDrawable=new InsetDrawable(getResources().getDrawable(R.drawable.image4), 20, 30, 30, 20);        

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.