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


Java RecyclerView.LayoutManager方法代碼示例

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


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

示例1: onAttachedToRecyclerView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridManager = ((GridLayoutManager) manager);
        gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return (isHeader(position) || isFooter(position) || isRefreshHeader(position))
                        ? gridManager.getSpanCount() : 1;
            }
        });
    }
    adapter.onAttachedToRecyclerView(recyclerView);
}
 
開發者ID:leobert-lan,項目名稱:UiLib,代碼行數:17,代碼來源:LRecyclerView.java

示例2: onCreateView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_recipe_list, container, false);
    ButterKnife.bind(this, view);

    this.adapter = new RecipeCardAdapter();
    this.adapter.setOnRecipeClickListener(this);

    RecyclerView.LayoutManager lm = new LinearLayoutManager(
            getActivity(), LinearLayoutManager.VERTICAL, false);

    this.recyclerView.setLayoutManager(lm);
    this.recyclerView.setAdapter(adapter);

    return view;
}
 
開發者ID:AndrejJurkin,項目名稱:udacity-baking-app-mvvm-rxjava-dagger,代碼行數:18,代碼來源:RecipeListFragment.java

示例3: onChildDraw

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int
        actionState, boolean isCurrentlyActive) {
    //判斷當前是否是swipe方式:側滑。
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        //1.ItemView--ViewHolder; 2.側滑條目的透明度程度關聯誰?dX(delta增量,範圍:當前條目-width~width)。
        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        float alpha = 1;
        if (layoutManager instanceof LinearLayoutManager) {
            int orientation = ((LinearLayoutManager) layoutManager).getOrientation();
            if (orientation == LinearLayoutManager.HORIZONTAL) {
                alpha = 1 - Math.abs(dY) / viewHolder.itemView.getHeight();
            } else if (orientation == LinearLayoutManager.VERTICAL) {
                alpha = 1 - Math.abs(dX) / viewHolder.itemView.getWidth();
            }
        }
        viewHolder.itemView.setAlpha(alpha);//1~0
    }
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
開發者ID:leobert-lan,項目名稱:UiLib,代碼行數:21,代碼來源:DefaultItemTouchHelperCallback.java

示例4: fetchMatches

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void fetchMatches(Context context) {
    users = new ArrayList<>();
    Client clientone = new Client().setUsername("bunnypassion");
    Client clienttwo = new Client().setUsername("butterscotchseven");
    Client clientthree = new Client().setUsername("danieldas");
    users.add(clientone);
    users.add(clienttwo);
    users.add(clienttwo);
    users.add(clienttwo);
    users.add(clientthree);

    matchesAdapter = new MatchesAdapter(users, getContext());
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);

    matchesView.setLayoutManager(layoutManager);
    matchesView.setAdapter(matchesAdapter);

    matchesAdapter.notifyDataSetChanged();

}
 
開發者ID:othreecodes,項目名稱:Dampp,代碼行數:21,代碼來源:HomeFragment.java

示例5: getOrientation

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private int getOrientation(RecyclerView parent) {
    final RecyclerView.LayoutManager lm = parent.getLayoutManager();
    if (lm instanceof LinearLayoutManager) {
        return ((LinearLayoutManager) lm).getOrientation();
    } else {
        throw new IllegalStateException("Use only with a LinearLayoutManager!");
    }
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:9,代碼來源:SearchDivider.java

示例6: createLayoutManager

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected RecyclerView.LayoutManager createLayoutManager() {
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 2);
    proteinAdapter.setSpanCount(2);
    gridLayoutManager.setSpanSizeLookup(proteinAdapter.getSpanSizeLookup());
    return gridLayoutManager;
}
 
開發者ID:gejiaheng,項目名稱:Protein,代碼行數:8,代碼來源:UserShotListFragment.java

示例7: findLastVisibleItemPosition

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * @param layoutManager the given subclass of {@link RecyclerView.LayoutManager}
 * @return the last visible item position among such positions in all spans
 */
public static <T extends RecyclerView.LayoutManager> int findLastVisibleItemPosition(@NonNull final T layoutManager) {
    final int count = getSpanCount(layoutManager);
    int position;
    int end = RecyclerView.NO_POSITION;
    for (int i = count - 1; i >= 0; i--) {
        position = findLastVisibleItemPosition(layoutManager, i);
        if (end == RecyclerView.NO_POSITION || end < position) {
            end = position;
        }
    }
    return end;
}
 
開發者ID:Tenor-Inc,項目名稱:tenor-android-core,代碼行數:17,代碼來源:AbstractLayoutManagerUtils.java

示例8: isNestedScrollViewTop

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private boolean isNestedScrollViewTop() {
    RecyclerView.LayoutManager layoutManager = mNestedScrollViewProvider.getNestedScrollView().getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        int position = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        View itemView = mNestedScrollViewProvider.getNestedScrollView().getChildAt(0);
        if (itemView == null || (position == 0 && itemView.getTop() == 0)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:Drizzlezhang,項目名稱:ZhihuUserProfile,代碼行數:12,代碼來源:ZhihuUserProfileLayout.java

示例9: setLayoutManager

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
     * Provide the layoutManager for the recycler view.
     */
    public void setLayoutManager(RecyclerView.LayoutManager layout) {
//        boolean hadLayoutManager = mLayoutManager != null;
        mLayoutManager = layout;
        if (mRecyclerView != null) {
            mRecyclerView.setLayoutManager(layout);
        }
    }
 
開發者ID:halohoop,項目名稱:AndroidDigIn,代碼行數:11,代碼來源:RecyclerFragment.java

示例10: onScrolled

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LayoutManagerType.LinearLayout;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LayoutManagerType.GridLayout;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LayoutManagerType.StaggeredGridLayout;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LinearLayout:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GridLayout:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case StaggeredGridLayout:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }

}
 
開發者ID:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:38,代碼來源:EndlessRecyclerOnScrollListener.java

示例11: configRecycleView

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * 配置recycleview
 *
 * @param recyclerView
 * @param layoutManager
 */
private void configRecycleView(RecyclerView recyclerView, RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以確定每個item的高度是固定的,設置這個選項可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    mSwipeRefreshLayout.setProgressViewOffset(false, -200, -200);
    mSwipeRefreshLayout.setRefreshing(false);
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:15,代碼來源:UserRecordActivity.java

示例12: isLastSpan

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public boolean isLastSpan(int itemPosition, RecyclerView parent) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
        if ((itemPosition + 1) % spanCount == 0)
            return true;
    }
    return false;
}
 
開發者ID:GitLqr,項目名稱:MaterialDesignDemo,代碼行數:10,代碼來源:MyDecorationTwo.java

示例13: getVisibleItemCount

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public int getVisibleItemCount(){
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    //only LinearLayoutManager can find last visible
    if(layoutManager instanceof LinearLayoutManager){
        LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
        int firstPosition = linearManager.findFirstVisibleItemPosition();
        int lastPosition = linearManager.findLastVisibleItemPosition();
        return lastPosition - firstPosition + 1;
    }else {
        throw new UnsupportedOperationException("only for Linear RecyclerView ");
    }
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:13,代碼來源:ListFragment.java

示例14: initViews

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initViews(){

        recyclerView.setHasFixedSize(true);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        ArrayList androidVersions = prepareData();
        DataAdapter adapter = new DataAdapter(getActivity(),androidVersions);
        recyclerView.setAdapter(adapter);

    }
 
開發者ID:Ronak-59,項目名稱:Trinity-App,代碼行數:12,代碼來源:SportsActivity.java

示例15: getLayoutManager

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public RecyclerView.LayoutManager getLayoutManager() {
    return mLayoutManager;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:EndlessRecyclerOnScrollListener.java


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