[英]What are insets in android?
我是android开发的初学者。 我最近在看一些其他代码并且喜欢一些函数view.onApplyWindowInsets(windowInsets), windowInsets.getSystemWindowInsetTop()
。 这个词在同一个应用程序中一次又一次地被使用。
我试着用谷歌搜索它并找到了InsetDrwable
类, InsetDrwable
有解释
将另一个 Drawable 插入指定距离的 Drawable。 当 View 需要小于 View 实际边界的背景时使用。
有人可以向我解释一下Insets
的含义以及上面的那些代码是什么意思吗?
一个例子的解释将不胜感激。
假设你有一个 TextView,你需要给 TextView 添加一个背景。 但是,另一方面,您不希望背景扫描整个 View(TextView),因此,您需要使用 Insets。
一个 Drawable,它按指定的距离或内容边界的一部分插入另一个 Drawable。 当 View 需要小于 View 实际边界的背景时使用。
背景可以是 Drawable。 因此,您需要在 xml 文件 (activity_main.xml)“例如”中使用<inset>
属性。
然后,在使用<inset>
标签后,您可以指定一些属性,例如:
<inset
android:drawable="@drawable/(Enter the file name under drawable)"
android:insetBottom="4dp"
android:insetTop="4dp"/>
有关更多信息,请查看 Android developer.com 上的InsetDrawable
希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.