Android 无法在自定义MediaController子类中截获触摸事件

Android 无法在自定义MediaController子类中截获触摸事件,android,user-interface,mediacontroller,Android,User Interface,Mediacontroller,我试图将MediaController子类化,以使其完全可定制(我不采用这种方法,因为我有一些无法更改的遗留代码) 我的代码大致如下所示: mc_layout.xml: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Linea

我试图将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窗口而不是调用重写的onTouchEvent时,正如我所料,MediaController的onTouch装饰窗口被调用,正如调用堆栈中所示:

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、 我和lv一起工作。9 API

谢谢

我找到了! 问题在于使用FrameLayout时,它只能显示单个项,并且其大小为最大子项的大小。因此,在我的情况下,它不够大,无法像我预期的那样覆盖整个屏幕。因此,装饰窗口最终处理了触摸事件,这非常有意义

无论如何,工作布局现在看起来像:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ...>

        // Some buttons

    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ... >

        // Some buttons

    </LinearLayout>
    ....
</RelativeLayout>   

//一些钮扣
//一些钮扣
....
希望有一天这会对某人有所帮助:)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ...>

        // Some buttons

    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ... >

        // Some buttons

    </LinearLayout>
    ....
</RelativeLayout>