Android中拦截屏幕更新

发布于 2025-01-05 05:02:56 字数 657 浏览 2 评论 0原文

android 是否可以拦截屏幕更新?

我实现了一个自定义 LinearLayout 覆盖了 onDraw() 方法,但只有当我不单击子元素而是单击其他位置时才会调用它。

例如,当我在此视图组中有一个按钮并且单击此按钮时,将不会在根级别调用 onDraw() 方法。另一方面,如果我触摸 TextView,则将在根级别调用 onDraw() 。似乎某些元素消耗了 onDraw() 方法,并且不将其传递给父元素。除了扩展每个可能的子视图并进行自定义实现之外,是否还有另一种方法或事件可以捕获以获取根视图及其子视图在根级别的所有更新?

编辑:也许我必须澄清一下。我的目的是在每次子视图发生变化时获取它们的位图。因此,例如,如果按钮是子视图,我想将视图绘制到位图(获取绘图缓存或手动调用 draw() 到自定义画布)。使用例如 onClickListener 的问题是,按钮状态在单击时实际上是“单击”,我还需要在单击之后和之前设置的按钮状态的图像(http://developer.android. com/design/style/touch-feedback.html)。另一个问题是,我不知道存在哪些以及有多少子视图,这应该适用于每个可能创建的布局。所以 onClickListeners 也没有选择,除非我会迭代所有子项并检查它们是什么类型。但不同州之间仍然存在问题。

is it possible to intercept screen updates in android?

I implemented a custom LinearLayout overrode the onDraw() method, but it will be only invoked when I do not click on child elements but somewhere else.

E.g. when i have a button in this view group and I click on this button, the onDraw() method won't be invoked on root level. On the other hand, if I touch a TextView the onDraw() will be invoked on root level. It seems like some elements consume the onDraw() method and do not pass it to the parent. Is there another method or event I can catch to get all the updates of the root view and its children on root level, except of extending each possible child and make custom implementations?

Edit: Maybe I have to clarify it a little bit. My purpose is to get bitmaps of the child views, every time they change. So e.g. if a button is a child view, I want to draw the view to a bitmap (get the drawing cache or invoking draw() manually to a custom canvas). The problem by using e.g. onClickListener is, that the the button state, while clicked, is actually "clicked", i need also an image of the button state which is set after and before it was clicked (http://developer.android.com/design/style/touch-feedback.html). Another problem is also, that I don't know which and how many child views are present, this should work for every possible created layout. So onClickListeners are also no option, except I would iterate through all children and check which type they are. But still there is the problem with the different states.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残月升风 2025-01-12 05:02:56

不要为根布局的子布局创建onclick侦听器

dont create onclick listeners for child layouts of root layout.

甜尕妞 2025-01-12 05:02:56

不要为子布局创建 onClick 侦听器并让您的活动实现 onClickListener。重写您的 Activity 的 onClick 方法,您可以处理其中的任何点击。

public class Acitivity implements OnClickListener
{

    @Override
    public void onClick(View v) 
    {
          //Handle clicks here
    }

}

Don't create onClick listeners for child layouts and have your activity implement an onClickListener. Override the onClick method for your activity and you can handle any clicks in there.

public class Acitivity implements OnClickListener
{

    @Override
    public void onClick(View v) 
    {
          //Handle clicks here
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文