Java Code Examples for android.support.v7.widget.RecyclerView#requestLayout()

The following examples show how to use android.support.v7.widget.RecyclerView#requestLayout() . 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
Source File: GridLayoutManager.java    From TvRecyclerView with Apache License 2.0 5 votes vote down vote up
private void scrollToSelection(RecyclerView parent, int position, int subPosition,
                               boolean smooth, int primaryScrollExtra) {
    View view = findViewByPosition(position);
    if (view != null) {
        mInSelection = true;
        scrollToView(view, smooth);
        mInSelection = false;
    } else {
        mFocusPosition = position;
        if (mIsSlidingChildViews) {
            return;
        }
        if (smooth) {
            if (!hasDoneFirstLayout()) {
                Log.w(TAG, "setSelectionSmooth should "
                        + "not be called before first layout pass");
                return;
            }
            position = startPositionSmoothScroller(position);
            if (position != mFocusPosition) {
                // gets cropped by adapter size
                mFocusPosition = position;
            }
        } else {
            parent.requestLayout();
        }
    }
}
 
Example 2
Source File: RecyclerViewLiteModeMapActivity.java    From Airbnb-Android-Google-Map-View with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view_lite_mode_map);
    getSupportActionBar().setTitle("Map View Lite Mode");

    mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
    mRecyclerView.setHasFixedSize(false);
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);

    mAdapter = new RecyclerViewLiteModeAdapter(addresses, this);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.requestLayout();


    mAddressModel=new AddressModel(this, new BaseInterface() {
        @Override
        public void handleNetworkCall(Object object, int requestCode) {
            if (requestCode == NetworkConstants.ADDRESS_REQUEST) {
                if (object instanceof ArrayList) {
                    addresses = new ArrayList<>();
                    addresses = (ArrayList) object;
                    mAdapter = new RecyclerViewLiteModeAdapter(addresses, RecyclerViewLiteModeMapActivity.this);
                    mRecyclerView.setAdapter(mAdapter);
                    mAdapter.notifyDataSetChanged();
                    mRecyclerView.requestLayout();
                }
                else{
                    Toast.makeText(RecyclerViewLiteModeMapActivity.this, (String)object,Toast.LENGTH_LONG).show();
                }
            }
        }
    });

    mAddressModel.fetchAddressFromServer();
}
 
Example 3
Source File: ResizeHeightPostCallback.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
public void onPostCallback(int position, T item, int itemLayoutId, ViewHelper helper) {
    RecyclerView rv ;
    if( ( rv = mWeakRecyclerView.get()) == null){
        return;
    }
    mSizeMap.put(position,rv.getLayoutManager().getDecoratedMeasuredHeight(helper.getRootView()));
    rv.getLayoutParams().height = calculateHeight(rv.getLayoutManager(),mSizeMap);
    rv.requestLayout();
}
 
Example 4
Source File: ListViewActivity.java    From Airbnb-Android-Google-Map-View with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_view);

    getSupportActionBar().setTitle("List View");
    mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_lisiting);

    mLoadingMoreDataProgress = (ProgressBar) findViewById(R.id.loading_progress);


    mLoadingMoreDataProgress.getIndeterminateDrawable().setColorFilter(0xff00b1c7, PorterDuff.Mode.MULTIPLY);
    mLoadingMoreDataProgress.setVisibility(View.GONE);


    mRecyclerView.setHasFixedSize(false);
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new ListViewAdapter(mAddressList, this);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.requestLayout();

    mSwipeLayout.setColorSchemeResources(R.color.gomalan_bule_bg);

    mAddressModel=new AddressModel(this, new BaseInterface() {
        @Override
        public void handleNetworkCall(Object object, int requestCode) {
            if (requestCode == NetworkConstants.ADDRESS_REQUEST) {
                if (object instanceof ArrayList) {
                    mAddressList = new ArrayList<>();
                    mAddressList = (ArrayList) object;
                    mAdapter = new ListViewAdapter(mAddressList, ListViewActivity.this);
                    mRecyclerView.setAdapter(mAdapter);
                    mAdapter.notifyDataSetChanged();
                }
                else{
                    Toast.makeText(ListViewActivity.this, (String)object,Toast.LENGTH_LONG).show();
                }
            }
        }
    });



    mAddressModel.fetchAddressFromServer();

}
 
Example 5
Source File: GridLayoutManager.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
private void scrollToSelection(RecyclerView parent, int position, boolean smooth) {
    View view = findViewByPosition(position);
    if (view != null) {
        mInSelection = true;
        scrollToView(view, smooth);
        mInSelection = false;
    } else {
        mFocusPosition = position;
        mFocusPositionOffset = 0;
        if (!mLayoutEnabled) {
            return;
        }
        if (smooth) {
            if (!hasDoneFirstLayout()) {
                Log.w(getTag(), "setSelectionSmooth should " +
                        "not be called before first layout pass");
                return;
            }
            LinearSmoothScroller linearSmoothScroller =
                    new LinearSmoothScroller(parent.getContext()) {
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    if (getChildCount() == 0) {
                        return null;
                    }
                    final int firstChildPos = getPosition(getChildAt(0));
                    final int direction = targetPosition < firstChildPos ? -1 : 1;
                    if (mOrientation == HORIZONTAL) {
                        return new PointF(direction, 0);
                    } else {
                        return new PointF(0, direction);
                    }
                }
                @Override
                protected void onTargetFound(View targetView,
                        RecyclerView.State state, Action action) {
                    if (hasFocus()) {
                        targetView.requestFocus();
                    }
                    dispatchChildSelected();
                    if (getScrollPosition(targetView, mTempDeltas)) {
                        int dx, dy;
                        if (mOrientation == HORIZONTAL) {
                            dx = mTempDeltas[0];
                            dy = mTempDeltas[1];
                        } else {
                            dx = mTempDeltas[1];
                            dy = mTempDeltas[0];
                        }
                        final int distance = (int) Math.sqrt(dx * dx + dy * dy);
                        final int time = calculateTimeForDeceleration(distance);
                        action.update(dx, dy, time, mDecelerateInterpolator);
                    }
                }
            };
            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        } else {
            mForceFullLayout = true;
            parent.requestLayout();
        }
    }
}