2012-06-11 21 views

回答

6

在您的活动中,您可以覆盖onTouchEvent并始终使用return true;来指示您正在处理触摸事件。

您可以找到该功能的文档there

编辑这里是你可以禁用在整个屏幕上触摸的一种方式,而不是通过一个处理每一个观点...首先改变你目前的布局是这样的:

<FrameLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    < .... put your current layout here ... /> 

    <TouchBlackHoleView 
     android:id="@+id/black_hole" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
</FrameLayout> 

,然后定义您的自定义鉴于像这样的东西:

public class TouchBlackHoleView extends View { 
    private boolean touch_disabled=true; 
    @Override 
    public boolean onTouchEvent(MotionEvent e) { 
     return touch_disabled; 
    } 
    public disable_touch(boolean b) { 
     touch_disabled=b; 
    } 
} 

然后,在活动中,您可以禁用与

触摸

,并使其与

black_hole.disable_touch(false); 
+0

'视图视图= findViewById(R.id.whole_view); \t查看。setOnTouchListener(新OnTouchListener(){ 公共布尔onTouch(视图V,MotionEvent事件){// TODO自动生成方法存根 返回true;} }); ' 我写这在我的动画的开端,但它没有工作 请你告诉我在哪里,我错了 –

+0

这里whole_view是我的主要布局 –

+0

的id是什么样的看法是它和你有什么禁用?它是一个按钮?一个ScrollView? ...? – Matthieu

1

答案回到这个问题

for (int i = 1; i < layout.getChildCount(); i++) { TableRow row = (TableRow) layout.getChildAt(i); row.setClickable(false);

选择其中有各方面的意见表布局中的所有行,并禁止他们

0

简单的实现方法是添加跨越式布局(将其添加到xml填充父级高度和宽度中)。

在动画开始:transaparentlayout.setClickable(true);

在动画结束:transaparentlayout.setClickable(false);

0

最后我把为@Matthieu的一个基本答案,并使其发挥作用这样的方式。我决定公布我的答案,因为我花了30分钟才明白我为什么会出错。

XML

<...your path to this view and in the end --> .TouchBlackHoleView 
    android:id="@+id/blackHole" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

公共类TouchBlackHoleView扩展视图{ 私人布尔touchDisable = FALSE;

public TouchBlackHoleView(Context context) { 
    super(context); 
} 

public TouchBlackHoleView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public TouchBlackHoleView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    return touchDisable; 
} 

public void disableTouch(boolean value){ 
    touchDisable = value; 
} 
} 

使用

blackHole = (TouchBlackHoleView) findViewById(R.id.blackHole); 
blackHole.disableTouch(true); 

享受