问题重现,如下图:
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
/**
*
* @author 作者:易皇星
*
* @toTODO 类描述: 可直接控制所有子控件是否可点击的LinearLayout
*/
public class ChildClickableLinearLayout extends LinearLayout {
// 子控件是否可以接受点击事件
private boolean childClickable = true;
public ChildClickableLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public ChildClickableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public ChildClickableLinearLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/**
* 重写onInterceptTouchEvent()
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// 返回true则拦截子控件所有点击事件,如果childclickable为true,则需返回false
return !childClickable;
}
/**
* 然后就像正常LinearLayout一样使用这个控件就可以了。在需要的时候调用一下setChildClickable,
* 参数为true则所有子控件可以点击,false则不可点击。
*
* @param clickable
*/
public void setChildClickable(boolean clickable) {
childClickable = clickable;
}
}
使用:
ll_home_navigation = (ChildClickableLinearLayout)getView(R.id.ll_home_navigation);
ll_home_navigation.setChildClickable(false);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之家整理,本文链接:https://www.bmabk.com/index.php/post/12859.html