简体   繁体   English

android 中的插图是什么?

[英]What are insets in android?

I am beginner at android development.我是android开发的初学者。 I was recently looking at some one else code and fond some functions view.onApplyWindowInsets(windowInsets), windowInsets.getSystemWindowInsetTop() .我最近在看一些其他代码并且喜欢一些函数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我试着用谷歌搜索它并找到了InsetDrwable类, InsetDrwable有解释

A Drawable that insets another Drawable by a specified distance.将另一个 Drawable 插入指定距离的 Drawable。 This is used when a View needs a background that is smaller than the View's actual bounds.当 View 需要小于 View 实际边界的背景时使用。

Can some one explain me what is the meaning on Insets and what those piece of code up there meant?有人可以向我解释一下Insets的含义以及上面的那些代码是什么意思吗?

A explanation with an example will be appreciated.一个例子的解释将不胜感激。

Suppose you have a TextView and you need to add a background to the TextView.假设你有一个 TextView,你需要给 TextView 添加一个背景。 But, on the other hand, you don't want the background to scan the entire View (TextView), therefore, you need to use Insets.但是,另一方面,您不希望背景扫描整个 View(TextView),因此,您需要使用 Insets。

A Drawable that insets another Drawable by a specified distance or fraction of the content bounds.一个 Drawable,它按指定的距离或内容边界的一部分插入另一个 Drawable。 This is used when a View needs a background that is smaller than the View's actual bounds.当 View 需要小于 View 实际边界的背景时使用。

The background can be a Drawable.背景可以是 Drawable。 Hence you need to use the <inset> attribute inside your xml file (activity_main.xml) "For Example".因此,您需要在 xml 文件 (activity_main.xml)“例如”中使用<inset>属性。

Then, after using the <inset> tag, you can specify some attributes such as:然后,在使用<inset>标签后,您可以指定一些属性,例如:

<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有关更多信息,请查看 Android developer.com 上的InsetDrawable

Hope this helps!希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM