Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are insets in android?

Tags:

android

insets

I am beginner at android development. I was recently looking at some one else code and fond some functions view.onApplyWindowInsets(windowInsets), windowInsets.getSystemWindowInsetTop(). And this word was used again and again in the same app.

I tried googling it and found InsetDrwable class with explanation

A Drawable that insets another Drawable by a specified distance. This is used when a View needs a background that is smaller than the View's actual bounds.

Can some one explain me what is the meaning on Insets and what those piece of code up there meant?

A explanation with an example will be appreciated.

like image 310
Saran Sankaran Avatar asked Jul 27 '16 19:07

Saran Sankaran


People also ask

What is inset drawable in Android?

android.graphics.drawable.InsetDrawable. A Drawable that insets another Drawable by a specified distance or fraction of the content bounds. This is used when a View needs a background that is smaller than the View's actual bounds. It can be defined in an XML file with the <inset> element.

What is a window inset?

android.view.WindowInsets. Describes a set of insets for window content. WindowInsets are immutable and may be expanded to include more inset types in the future. To adjust insets, use one of the supplied clone methods to obtain a new WindowInsets instance with the adjusted properties.


1 Answers

Suppose you have a TextView and you need to add a background to the TextView. But, on the other hand, you don't want the background to scan the entire View (TextView), therefore, you need to use Insets.

A Drawable that insets another Drawable by a specified distance or fraction of the content bounds. This is used when a View needs a background that is smaller than the View's actual bounds.

The background can be a Drawable. Hence you need to use the <inset> attribute inside your xml file (activity_main.xml) "For Example".

Then, after using the <inset> tag, you can specify some attributes such as:

<inset     android:drawable="@drawable/(Enter the file name under drawable)"     android:insetBottom="4dp"     android:insetTop="4dp"/> 

For more information please have a look at InsetDrawable on Android developer.com

Hope this helps!

like image 110
issa.ayoub.dev Avatar answered Sep 30 '22 22:09

issa.ayoub.dev