Java Code Examples for android.view.ViewGroup#removeViewInLayout()

The following examples show how to use android.view.ViewGroup#removeViewInLayout() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * remove a view
 *
 * @param parent
 * @param view
 */
public static void removeView(ViewGroup parent, View view) {
    //这里不使用post来做,这样代码更可控,而是改为将refresh下拉动作延后一帧处理,见@link
    //这里调用removeViewInLayout方法,可以在onLayout的时候调用,否则会产生问题
    if (parent != null && view != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (parent.isInLayout()) {
                parent.removeViewInLayout(view);
            } else {
                parent.removeView(view);
            }
        } else {
            parent.removeView(view);
        }
    }
}
 
Example 2
protected void bindSwipeToRefresh(ViewGroup v) {
	mSwipeRefresh = new SwipeUpAndDownRefreshLayout(getActivity());
	
	// Move child to SwipeRefreshLayout, and add SwipeRefreshLayout to root view
	v.removeViewInLayout(mList);
	v.addView(mSwipeRefresh, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	mSwipeRefresh.addView(mList, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	
	mSwipeRefresh.setOnRefreshListener(this);
	mSwipeRefresh.setColorScheme(R.color.ptr_green, R.color.ptr_orange, R.color.ptr_red, R.color.ptr_blue);
}
 
Example 3
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	// Share the view
	ViewGroup v = (ViewGroup) inflater.inflate(R.layout.home_timeline, null);
	
	mList = (ListView) v.findViewById(R.id.home_timeline);
	
	mSwipeRefresh = new SwipeUpAndDownRefreshLayout(getActivity());

	// Move child to SwipeRefreshLayout, and add SwipeRefreshLayout to root view
	v.removeViewInLayout(mList);
	v.addView(mSwipeRefresh, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	mSwipeRefresh.addView(mList, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

	mSwipeRefresh.setOnRefreshListener(this);
	mSwipeRefresh.setColorScheme(R.color.ptr_green, R.color.ptr_orange, R.color.ptr_red, R.color.ptr_blue);
	
	mApiCache = new DirectMessagesUserApiCache(getActivity());
	mAdapter = new DirectMessageUserAdapter(getActivity(), mApiCache.mUsers);
	mList.setAdapter(mAdapter);
	mList.setOnItemClickListener(this);
	
	mApiCache.loadFromCache();
	
	if (mApiCache.mUsers.getSize() == 0) {
		onRefresh();
	}
	
	return v;
}
 
Example 4
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	// Share the layout of Home Time Line
	ViewGroup v = (ViewGroup) inflater.inflate(R.layout.home_timeline, null);
	
	// Init
	mList = (ListView) v.findViewById(R.id.home_timeline);
	mUsers = new UserListModel();
	mAdapter = new UserAdapter(getActivity(), mUsers);
	mList.setAdapter(mAdapter);
	mList.setOnItemClickListener(this);
	mSwipeRefresh = new SwipeUpAndDownRefreshLayout(getActivity());

	// Move child to SwipeRefreshLayout, and add SwipeRefreshLayout to root view
	v.removeViewInLayout(mList);
	v.addView(mSwipeRefresh, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
	mSwipeRefresh.addView(mList, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

	mSwipeRefresh.setOnRefreshListener(this);
	mSwipeRefresh.setColorScheme(R.color.ptr_green, R.color.ptr_orange, R.color.ptr_red, R.color.ptr_blue);
	
	if (mUid != null) {
		onRefresh(); 
	}
	
	return v;
}
 
Example 5
Source Project: AndroidPlugin   File: ViewStub.java    License: MIT License 4 votes vote down vote up
/**
 * Inflates the layout resource identified by {@link #getLayoutResource()}
 * and replaces this StubbedView in its parent by the inflated layout
 * resource.
 * 
 * @return The inflated layout resource.
 * 
 */
public View inflate() {
    final ViewParent viewParent = getParent();

    if (viewParent != null && viewParent instanceof ViewGroup) {
        if (mLayoutResource != 0) {
            final ViewGroup parent = (ViewGroup) viewParent;
            final LayoutInflater factory;
            if (mInflater != null) {
                factory = mInflater;
            } else {
                factory = LayoutInflater.from(getContext());
            }
            final View view = factory.inflate(mLayoutResource, parent,
                    false);

            if (mInflatedId != NO_ID) {
                view.setId(mInflatedId);
            }

            final int index = parent.indexOfChild(this);
            parent.removeViewInLayout(this);

            final ViewGroup.LayoutParams layoutParams = getLayoutParams();
            if (layoutParams != null) {
                parent.addView(view, index, layoutParams);
            } else {
                parent.addView(view, index);
            }

            mInflatedViewRef = new WeakReference<View>(view);

            if (mInflateListener != null) {
                mInflateListener.onInflate(this, view);
            }

            return view;
        } else {
            throw new IllegalArgumentException(
                    "ViewStub must have a valid layoutResource");
        }
    } else {
        throw new IllegalStateException(
                "ViewStub must have a non-null ViewGroup viewParent");
    }
}