嵌套滚动中的华为地图 [英] Huawei Map inside Nested Scroll
本文介绍了嵌套滚动中的华为地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Touch Event上进行拦截,所以我创建了CustomSupportMapFragment,但从未获得过onTouchEvent,我具有与GMS版本相同的代码,并且运行正常.所以我不知道.这是我的代码:
I need to intercept on Touch Event, so I created a CustomSupportMapFragment, but never get the onTouchEvent, I have the same code for the GMS version and goes fine. So I don't know. Here is my code:
class TCSupportMapFragment: SupportMapFragment() {
private var mListener: OnTouchListener? = null
override fun onCreateView(inflater: LayoutInflater, parent: ViewGroup?, savedInstanceState: Bundle?): View {
val layout = super.onCreateView(inflater, parent, savedInstanceState)
val frameLayout = TouchableWrapper(requireContext())
frameLayout.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.transparent))
(layout as ViewGroup).addView(frameLayout, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
return layout
}
fun setListener(listener: OnTouchListener?) {
mListener = listener
}
interface OnTouchListener {
fun onTouch()
}
inner class TouchableWrapper(context: Context) : FrameLayout(context) {
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> mListener?.onTouch()
MotionEvent.ACTION_UP -> mListener?.onTouch()
}
return super.dispatchTouchEvent(event)
}
}
}
活动中:
override fun onTouchListener() {
this.binding.nestedScroll.requestDisallowInterceptTouchEvent(true)
}
推荐答案
您应该在执行逻辑的地方截取触摸,而不是使用以下命令构建新的片段类型:
You should intercept the touch where you are doing the logic instead of building the new fragment type using the following:
View view = inflater.inflate(R.layout.fragment_test, container, false);
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE){
//do something
}
return true;
}
});
//here the rest of your codereturn view;
您还可以在此处引用一些类似的主题.
You can also refer to some similar topics here.
这篇关于嵌套滚动中的华为地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文