0
我想要继承MediaController以使其完全可定制(我没有使用vidtry方法,因为我有一些遗留代码,我无法更改)。无法拦截自定义MediaController子类中的触摸事件
我的代码看起来大致是这样的:
mc_layout.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
...>
// Some buttons
</LinearLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
... >
// Some buttons
</LinearLayout>
mc_subclass.java:
public class MCSubclass extends MediaController {
private View mRoot;
GestureDetector mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
// Do something.
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// Do something.
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// Do something.
return false;
}
});
public MCSubclass(final Context context) {
super(context);
}
public boolean onTouchEvent(final MotionEvent event) {
// NEVER CALLED!
return mGestureDetector.onTouchEvent(event);
}
public final void setAnchorView(final View view) {
super.setAnchorView(view);
FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
);
removeAllViews();
View v = makeControllerView();
addView(v, frameParams);
}
private View makeControllerView() {
LayoutInflater inflate = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mRoot = inflate.inflate(R.layout.mc_layout, null);
initControllerView(mRoot);
return mRoot;
}
private void initControllerView(View v) {
mPlayButton = (ImageButton) v.findViewById(R.id.playBtn);
if (mPlayButton != null) {
mPlayButton.requestFocus();
mPlayButton.setOnClickListener(mOnClickListener);
}
// Init other views...
}
}
现在,我得到了所有控件都可见,并且它们都响应了它们的点击/触摸操作,但是当我点击/触摸MC窗口而不是调用重写的onTouchEvent时,我期望MediaController的装饰窗口的onTouch被调用,因为它可以在callstack中看到:
MediaController$1.onTouch(View, MotionEvent) line: 149
PhoneWindow$DecorView(View).dispatchTouchEvent(MotionEvent) line: 3762
PhoneWindow$DecorView(ViewGroup).dispatchTouchEvent(MotionEvent) line: 897
PhoneWindow$DecorView.dispatchTouchEvent(MotionEvent) line: 1862
ViewRoot.handleMessage(Message) line: 1809
ViewRoot(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
问题是我需要更换装饰窗口触摸监听器还是有更好的方法,我错过了什么?
p.s.我正在与lv合作。 9 API。
谢谢!