Android - 扩展ViewGroup而不是添加片段显示为空白

时间:2014-08-25 13:14:41

标签: java android android-fragments android-viewgroup

我正在推广名为Fragment的{​​{1}}。它布局合理,看起来我想要它。问题是我无法在Scanlist扩展Override onInterceptTouchEvent。所以我考虑扩展FragmentViewGroup,然后将Override onInterceptTouchEvent添加到Fragment。当我将ViewGroup添加到FragmentViewGroup未显示在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) {

    }
}

1 个答案:

答案 0 :(得分:1)

而不是FrameLayout使用overriden添加自定义FrameLayout 方法,你实际上并不需要FrameLayout因为它只有一个子节点,所以你可以在布局文件中放置自定义ListView