0

我正在扩展一个Fragment被调用的Scanlist. 它布局正确,看起来像我想要的那样。问题是我无法Override onInterceptTouchEvent在扩展的Fragment. 于是我想到了扩展ViewGroupOverride onInterceptTouchEvent然后把 my 添加FragmentViewGroup. 当我将我添加Fragment到 中时ViewGroupFragment不会出现在ViewGroup. 我知道ViewGroup那里是因为我能够LogonInterceptTouchEvent屏幕是空白的。

这是片段:

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>
4

1 回答 1

1

而不是 FrameLayout 添加您的自定义 FrameLayout 与覆盖的方法,你实际上并不需要那个 FrameLayout 因为它只有一个孩子,所以你可以将自定义 ListView 放在布局文件中

于 2014-08-25T14:39:41.830 回答