當前位置: 首頁>>代碼示例>>Java>>正文


Java RecyclerView.getParent方法代碼示例

本文整理匯總了Java中android.support.v7.widget.RecyclerView.getParent方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getParent方法的具體用法?Java RecyclerView.getParent怎麽用?Java RecyclerView.getParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.RecyclerView的用法示例。


在下文中一共展示了RecyclerView.getParent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupAlignment

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void setupAlignment(RecyclerView recycler) {
    if (!mAlreadyAligned) {
        //setting alignment of header
        ViewGroup.LayoutParams currentParams = getLayoutParams();
        FrameLayout.LayoutParams newHeaderParams;
        int width = ViewGroup.LayoutParams.WRAP_CONTENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL;
        if (currentParams != null) {
            newHeaderParams = new FrameLayout.LayoutParams(getLayoutParams()); //to copy all the margins
            newHeaderParams.width = width;
            newHeaderParams.height = height;
            newHeaderParams.gravity = gravity;
        } else {
            newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity);
        }
        RecyclerViewHeader.this.setLayoutParams(newHeaderParams);

        //setting alignment of recycler
        FrameLayout newRootParent = new FrameLayout(recycler.getContext());
        newRootParent.setLayoutParams(recycler.getLayoutParams());
        ViewParent currentParent = recycler.getParent();
        if (currentParent instanceof ViewGroup) {
            int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler);

            ((ViewGroup) currentParent).removeViewAt(indexWithinParent);
            recycler.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            newRootParent.addView(recycler);
            newRootParent.addView(RecyclerViewHeader.this);
            ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent);
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:34,代碼來源:RecyclerViewHeader.java

示例2: validateRecycler

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void validateRecycler(RecyclerView recycler, boolean headerAlreadyAligned) {
    RecyclerView.LayoutManager layoutManager = recycler.getLayoutManager();
    if (layoutManager == null) {
        throw new IllegalStateException("Be sure to call RecyclerViewHeader constructor after setting your RecyclerView's LayoutManager.");
    } else if (layoutManager.getClass() != LinearLayoutManager.class    //not using instanceof on purpose
            && layoutManager.getClass() != GridLayoutManager.class
            && !(layoutManager instanceof StaggeredGridLayoutManager)) {
        throw new IllegalArgumentException("Currently RecyclerViewHeader supports only LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager.");
    }

    if (layoutManager instanceof LinearLayoutManager) {
        if (((LinearLayoutManager) layoutManager).getOrientation() != LinearLayoutManager.VERTICAL) {
            throw new IllegalArgumentException("Currently RecyclerViewHeader supports only VERTICAL orientation LayoutManagers.");
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        if (((StaggeredGridLayoutManager) layoutManager).getOrientation() != StaggeredGridLayoutManager.VERTICAL) {
            throw new IllegalArgumentException("Currently RecyclerViewHeader supports only VERTICAL orientation StaggeredGridLayoutManagers.");
        }
    }

    if (!headerAlreadyAligned) {
        ViewParent parent = recycler.getParent();
        if (parent != null &&
                !(parent instanceof LinearLayout) &&
                !(parent instanceof FrameLayout) &&
                !(parent instanceof RelativeLayout)) {
            throw new IllegalStateException("Currently, NOT already aligned RecyclerViewHeader " +
                    "can only be used for RecyclerView with a parent of one of types: LinearLayout, FrameLayout, RelativeLayout.");
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:RecyclerViewHeader.java

示例3: setDataTwoWay

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * (偽)雙向 databinding: 自動調用 {@link TwoWayListVM#getLoadTask()},
 *      並自動觸發 {@link TwoWayListVM#setData(ObservableArrayList)}
 *      然後自動更新 RecyclerView
 *
 * @param container
 * @param vm
 * @param datas
 * @param <T>
 */
@BindingAdapter({"vm", "data"})
public static <T> void setDataTwoWay(final RecyclerView container, final ListVM<T> vm, List<T> datas){
    if(vm == null){
        return ;
    }
    setData(container, vm, datas);

    if(vm instanceof TwoWayListVM) {
        boolean isInited = container.getTag(R.id.db_inited) != null;
        if (!isInited) {
            container.setTag(R.id.db_inited, true);

            final TwoWayListVM<T> _vm = ((TwoWayListVM<T>) vm);

            loadData(container, _vm, null, null);
            // 若 parent 可下拉刷新,設置回調
            ViewParent parent = container.getParent();
            if (parent != null && parent instanceof TwoWayListVM.Refreshable) {
                final TwoWayListVM.Refreshable refreshable = (TwoWayListVM.Refreshable) parent;
                ((TwoWayListVM.Refreshable) parent).setOnRefresh(new TwoWayListVM.Refreshable.CallBack() {
                    @Override
                    public void onRefresh() {
                        loadData(container, _vm, null, refreshable);
                    }

                    @Override
                    public void onLoadMore() {
                        List<T> data = _vm.getData();
                        if (data.size() - 1 >= 0) {
                            loadData(container, _vm, data.get(data.size() - 1), refreshable);
                        }
                    }
                });
            }
        }
    }
}
 
開發者ID:fashare2015,項目名稱:MVVM-JueJin,代碼行數:48,代碼來源:RecyclerViewAdapter.java

示例4: onAttachedToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    ViewParent parent = recyclerView.getParent();
    if (parent != null && parent instanceof XRefreshView) {
        mParent = (XRefreshView) recyclerView.getParent();
        if (mParent != null && !observer.hasAttached()) {
            observer.setData(this, mParent);
            observer.attach();
            registerAdapterDataObserver(observer);
        }
    }
}
 
開發者ID:LonelyMushroom,項目名稱:aarLibrary,代碼行數:14,代碼來源:BaseRecyclerAdapter.java


注:本文中的android.support.v7.widget.RecyclerView.getParent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。