Android的clipToPadding属性有什么作用? [英] Android what does the clipToPadding Attribute do?

查看:25
本文介绍了Android的clipToPadding属性有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 clipToPadding 属性对 Android 中的 ViewGroup 有什么作用?

I would like to know what the clipToPadding attribute does for ViewGroup in Android ?

我已经浏览了文档和一些网站,但我没有遇到过真正解释它的作用和含义的,没有一个我能真正理解,所以我认为在这里问它可能是个好主意.

I've been through the docs and some websites but none I have come across actually explain what it does and what it means, well none that I could actually understand so I thought it might be a good idea to ask it here.

推荐答案

您可以将 clipToPadding 用于滚动视图.例如,假设您有一个列表视图,并且在顶部和底部设置了填充.通常,无论屏幕上哪些项目可见,填充都是可见的.下图表示一个包含 10 个项目的列表,但在屏幕上只有 4 个项目可见,使用默认的 clipToPadding 设置:

You can use clipToPadding for views that scroll. Say you have a listview for example and you having padding set on the top and bottom. Normally the padding is visible no matter which items are visible on the screen. The diagram below represents a list with 10 items but only 4 are visible on screen, with default clipToPadding settings:

  • (填充)
  • 第 4 项
  • 第 5 项
  • 第 6 项
  • 第 7 项
  • (填充)

现在,如果您要设置 clipToPadding="false" 而不是正常应用于整个视图,它只会将填充应用于最终项目,这就是您在同样的场景:

Now if you were to set clipToPadding="false" instead of just being applied normally to the entire view it only applies the padding to the end items, this is what you'd see in the same scenario:

  • 第 4 项
  • 第 5 项
  • 第 6 项
  • 第 7 项

现在,如果您滚动到列表的顶部或底部,您会看到以下内容:

Now if you were to scroll to the top or bottom of the list, this is what you would see:

  • (填充)
  • 第 1 项
  • 第 2 项
  • 第 3 项
  • 第 4 项

  • 第 7 项
  • 第 8 项
  • 第 9 项
  • 第 10 项
  • (填充)

一个实际的用法是,如果你有一个浮动操作按钮,你应该结合使用 clipToPadding 和底部填充来确保可以看到整个底部项目而不会被 FAB 阻挡.

A practical usage for this is if you have a Floating Action Button for example, you should use clipToPadding combined with bottom padding to ensure the entirety of the bottom item can be seen without being obstructed by the FAB.

有意义吗?

这篇关于Android的clipToPadding属性有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆