2
在我的代碼中,我使用預定義的XML佈局在我的Activity中生成視圖。我不會以編程方式創建它們,因此我無法找到重寫onInterceptTouchEvent方法的方法!有沒有辦法做到這一點?使用onInterceptTouchEvent
在我的代碼中,我使用預定義的XML佈局在我的Activity中生成視圖。我不會以編程方式創建它們,因此我無法找到重寫onInterceptTouchEvent方法的方法!有沒有辦法做到這一點?使用onInterceptTouchEvent
擴展你感興趣的類:
package com.myapp;
public class MyLayout extends RelativeLayout {
// Don't forget to include all the super constructors...
public void onInterceptTouchEvent(...){}
}
然後,你可以使用這個類在這樣的XML:
<com.myapp.MyLayout
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- acts just like a RelativeLayout, except for your custom code -->
</com.myapp.MyLayout>