我正在扩展一个Fragment
被调用的Scanlist
. 它布局正确,看起来像我想要的那样。问题是我无法Override onInterceptTouchEvent
在扩展的Fragment
. 于是我想到了扩展ViewGroup
,Override onInterceptTouchEvent
然后把 my 添加Fragment
到ViewGroup
. 当我将我添加Fragment
到 中时ViewGroup
,Fragment
不会出现在ViewGroup
. 我知道ViewGroup
那里是因为我能够Log
但onInterceptTouchEvent
屏幕是空白的。
这是片段:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mRootview = (ViewGroup) inflater.inflate(R.layout.scanlist, container, false);
mRootview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mSharedData = new SharedData(mContext);
costomListViewArr = mSharedData.getvins();
Resources res = getResources();
mList = (ListView)mRootview.findViewById(R.id.list);
mAdapter = new Scanvinadapter(mActivity, costomListViewArr, res);
mList.setAdapter(mAdapter);
mAdapter.setimplements(this);
ViewGroup vg = new Scanlistview(mContext);
vg.addView(mRootview);
return vg;
}
这是视图组
public class Scanlistview extends ViewGroup{
@SuppressWarnings("unused")
private final String TAG = this.getClass().getSimpleName();
LayoutInflater mInflater;
public Scanlistview(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
Log.v(TAG, "onInterceptTouchEvent");
return false;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
}
扫描列表.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flScanlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/vinlist_bg">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/vinlist_selector"
android:listSelector="@drawable/vinlist_selector"/>
</FrameLayout>