我正在推广名为Fragment
的{{1}}。它布局合理,看起来我想要它。问题是我无法在Scanlist
扩展Override onInterceptTouchEvent
。所以我考虑扩展Fragment
,ViewGroup
,然后将Override onInterceptTouchEvent
添加到Fragment
。当我将ViewGroup
添加到Fragment
时ViewGroup
未显示在Fragment
内。我知道ViewGroup
就在那里,因为我能够ViewGroup
Log
,但屏幕空白。
这是碎片:
onInterceptTouchEvent
这是ViewGroup
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;
}
scanlist.xml
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) {
}
}
答案 0 :(得分:1)
而不是FrameLayout使用overriden添加自定义FrameLayout 方法,你实际上并不需要FrameLayout因为它只有一个子节点,所以你可以在布局文件中放置自定义ListView