如何判断图像何时被剪裁?
如果我有一个包含 ImageView 的 LinearLayout,我如何编写代码来判断哪个(如果有的话)被屏幕边缘剪切?
<LinearLayout android:id="@+id/imagecontainer"
android:orientation="horizontal"
android:layoutHeight="wrap_content"
android:layoutWidth="fill_parent">
<ImageView android:id="@+id/image1" .../>
<ImageView android:id="@+id/image2" .../>
...
<ImageView android:id="@+id/imageN" .../>
</LinearLayout>
我想象类似的东西,如果没有人被剪裁,它会返回一个索引或 0。函数调用的语义并不重要......我只需要某种方法来判断是否存在剪切,如果有,是谁?
int whichImageIsClipped(LinearLayout root) { ... }
If I have a LinearLayout containing ImageViews, how could I write code to tell which, if any, is clipped by the edge of the screen?
<LinearLayout android:id="@+id/imagecontainer"
android:orientation="horizontal"
android:layoutHeight="wrap_content"
android:layoutWidth="fill_parent">
<ImageView android:id="@+id/image1" .../>
<ImageView android:id="@+id/image2" .../>
...
<ImageView android:id="@+id/imageN" .../>
</LinearLayout>
I imagine something like, which would return an index or 0 if nobody is clipped. The semantics of the function call aren't really important... I just need some way to tell if there is clipping and if so, who is it?
int whichImageIsClipped(LinearLayout root) { ... }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有点困难,但您可以尝试 getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point) 在你的每个孩子上。如果它返回 false,您就知道它完全看不见了。如果它返回 true,您将需要将返回的 Rect 与图像的预期大小进行比较。
这能满足您的需要吗?
这是代码,以防有人需要:
This may be a stretch, but you could try getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point) on each of your children. If it returns false, you know it's completely out of view. If it returns true, you will need to compare the returned Rect with the expected size of your image.
Does that work for what you need?
Here is the code, in case anyone needs it: