FrameLayout点击事件未触发 [英] FrameLayout click event is not firing
本文介绍了FrameLayout点击事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将Framelayour用于点击事件,并且在2天之前运行良好,但是现在不知道发生了什么事,因此它无法正常工作.
请有人帮我.
我的代码如下:
设计:
I have used Framelayour for click event and It was working fine before 2 days but don't know wat happend now it is not working.
Please someone help me.
My code is as below :
Design :
<FrameLayout
android:id="@+id/flWebpre"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<WebView
android:id="@+id/wvWebsite"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ProgressBar
android:id="@+id/pbWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_gravity="center_horizontal" />
</FrameLayout>
代码:
FrameLayout flWebPre = (FrameLayout) findViewById(R.id.flWebpre);
flWebPre.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (isExpanded) {
isExpanded = false;
new CollapseAnimation(slidingPanel, panelWidth,
TranslateAnimation.RELATIVE_TO_SELF, 0.70f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f,
0, 0.0f);
}
}
});
推荐答案
一种简单的方法是拦截所有触摸事件.默认情况下,ViewGroup#onInterceptTouchEvent
返回false
.
One easy way is to intercept all touch events. By default, ViewGroup#onInterceptTouchEvent
returns false
.
您可以创建自定义布局:
You may create a custom layout:
public class ClickableFrameLayout extends FrameLayout {
private OnClickListener mOnClickListener;
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
mOnClickListener = l;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return mOnClickListener != null;
}
// Standard constructors — just pass everything
public ClickableFrameLayout(final Context context) {
super(context);
}
public ClickableFrameLayout(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public ClickableFrameLayout(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ClickableFrameLayout(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}
这篇关于FrameLayout点击事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文