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

查看:101
本文介绍了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

OR

  • 项目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天全站免登陆