本文整理匯總了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);
}
示例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;
}
示例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);
}
示例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();
}
示例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!");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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 ");
}
}
示例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);
}
示例15: getLayoutManager
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public RecyclerView.LayoutManager getLayoutManager() {
return mLayoutManager;
}