如何禁用对Android的一个视图中的任何事件? [英] How to disable any event on a View in Android?

查看:138
本文介绍了如何禁用对Android的一个视图中的任何事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:如何禁止在Android的一个视图中的任何事件? (包括删除其focussability,就像我只是希望它是有视觉上但要inexistant的一切) 而且它在整个视图树工作? (比如,如果我禁用了根事件,所有的事件都将其子停用?)。

My question is simple: How to disable any event on a View in Android? (including removing its focussability, like I just want it to be there visually but be inexistant on everything else) And does it work on a whole view tree? (like if I disable events on the root, all the events will be disabled for its children?).

现在,在你说什么我已经尝试了所有的以下内容:

Now, before you say anything I have tried all the following:

  • setEnabled
  • setFocusable
  • setSelected
  • setClickable
  • setActivated

和这些方法都不能工作,认真。

And none of these methods appear to work, seriously.

我已经尝试过直接在的WebView ,以及对一切父布局,但我仍然能够与它进行交互。

I have tried them directly on a WebView, as well as on the parent layout on everything but I am still able to interact with it.

你知道吗?

谢谢!

编辑#1

这由在上添加需要被禁用不起作用,视图的顶视图中的溶液。事实上,它仍然有可能点击的内部景观,我试图用一个简单的例子:

The solution that consists in adding a view on top of the view that needs to be disabled doesn't work. Actually, it's still possible to click on the inner view, I have tried with a simple example:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#ff0000">
        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Click Me!"
        />
    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#00000000"
    />
</FrameLayout>

这仍然可以点击按钮

编辑#2

为什么我想这样做的原因是相关的<一个href="http://stackoverflow.com/questions/10029447/how-to-cleanly-superpose-scrollableviews-in-android">following 的问题,我问周前。

The reason why I want to do this is related to the following question that I asked weeks ago.

我有一个的ListView 充当导航栏是下一个查看保存的内容我的应用程序。这个实现的问题是,当我尝试滚动的ListView 时,有在层可调焦的看法在它的上面,以及在 ListView控件不会滚动,而是它的俯视图是需要重点(是这样的话时,有一个 web视图的EditText 等)。

What I have is a ListViewacting as a navigation bar which is underneath a View that holds the content of my app. The problem with this implementation is that when I try to scroll through the ListView when there is a focusable view in the layer on top of it, well the ListView doesn't scroll and instead it's the top view that takes focus (That's the case when there is a Webview or an EditText etc.).

所以,是中提到的其中一个答案,我可以在的WebView 通过覆盖 setOnTouchListener 但视图保持聚焦,我想这就是为什么我仍然有我的导航栏上的同一个问​​题的原因。

So yes as mentioned in one of the answers, I can disable any click events on a WebView by overriding setOnTouchListener but the view remains focussed and I think this is the reason why I am still having the same issue with my navigation bar.

推荐答案

简单的说一个观点你的观点之上。您可以通过设置view.visibility钮开启关闭=走/可见。

Simply put a view on top of your view. You can toggle it on off by setting view.visibility = gone/visible.

<FrameLayout>
<WebView/>
<FrameLayout This view will be on top/>
</FrameLayout>

编辑:在这个环节只是stumpled: http://stackoverflow.com/a/3856199/969325 基本上禁止所有的触摸事件的web视图。 Tryed是什么?

Just stumpled upon this link: http://stackoverflow.com/a/3856199/969325 Basically disables all touch event for the webview. Tryed that?

编辑2重新编辑:尝试设置了下面的列表视图的顶视图中的可见性

Edit 2 reedit: Try to set the visibility to gone for the the top view below your listview.

这篇关于如何禁用对Android的一个视图中的任何事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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