gpt4 book ai didi

android - 点击前景 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:51:02 27 4
gpt4 key购买 nike

我找不到完成这项工作的方法。

我的应用程序有 2 个带有许多 subview 的 FrameLayout(为简单起见假设为 ImageView),一个堆叠在另一个之上。

我的问题是,我需要 TOP 上的 FrameLayout 及其所有子项,让触摸通过它们,到达底层 FrameLayout(及其子项)。类似于 pointer-events:none in HTML 的东西适用于 TOP 框架布局的所有 ImageView 。

我已经在 FrameLayout 及其子项上尝试了 setClickable(false) 和 setEnabled(false),但是如果我单击禁用的子项(例如 ImageView),触摸将不会到达底层 ImageView(即子项)底部 FrameLayout 的)

以下代码是我禁用 FrameLayout 及其子项的最佳尝试(mSlideLayout 是父 FrameLayout,层是每个 imageview 子项)。我错过了什么吗??

/** Create the layers structure into the layout */
void create_layers() {
Context context=getActivity();
mSlideLayout.removeAllViews();
for (FunqLayer layer:mLayers) {
if (layer!=null) {
View v=layer.init_internal(context, mSlideLayout); // constructs the child layer, suppose it's an ImageView
if ((v!=null) && (mIsMuteTouches)) {
v.setEnabled(false);
v.setClickable(false);
// this should obviously let touches pass through but it doesnt :(
}
}
}
if (mIsMuteTouches) {
// also do the same in the FrameLayout itself with no luck :(
mSlideLayout.setEnabled(false);
mSlideLayout.setClickable(false);
}
}

最佳答案

是的,显然我错过了 onInterceptTouchEvent ,在框架布局中覆盖它并返回 true 使得上面的例程变得多余:

    FrameLayout slideLayout=new FrameLayout(getActivity()){
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mIsMuteTouches) return true;
return super.onInterceptTouchEvent(ev);
}
};

关于android - 点击前景 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16587900/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com