本文整理汇总了Java中android.support.v7.widget.OrientationHelper类的典型用法代码示例。如果您正苦于以下问题:Java OrientationHelper类的具体用法?Java OrientationHelper怎么用?Java OrientationHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OrientationHelper类属于android.support.v7.widget包,在下文中一共展示了OrientationHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLaunchpad
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
private void initLaunchpad() {
mLauncherView.setHasFixedSize(true);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL);
mLauncherView.setLayoutManager(layoutManager);
mLaunchpadAdapter = new LaunchpadAdapter(this);
SmartRecyclerAdapter wrap = new SmartRecyclerAdapter(mLaunchpadAdapter);
View footer = new View(this);
footer.setLayoutParams(new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, VUiKit.dpToPx(this, 60)));
wrap.setFooterView(footer);
mLauncherView.setAdapter(wrap);
mLauncherView.addItemDecoration(new ItemOffsetDecoration(this, R.dimen.desktop_divider));
ItemTouchHelper touchHelper = new ItemTouchHelper(new LauncherTouchCallback());
touchHelper.attachToRecyclerView(mLauncherView);
mLaunchpadAdapter.setAppClickListener((pos, data) -> {
if (!data.isLoading()) {
mLaunchpadAdapter.notifyItemChanged(pos);
mPresenter.launchApp(data);
}
});
}
示例2: getItemOffsets
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int spanCount = ((GridLayoutManager) parent.getLayoutManager()).getSpanCount();
int orientation = ((GridLayoutManager)parent.getLayoutManager()).getOrientation();
int position = parent.getChildLayoutPosition(view);
if(orientation == OrientationHelper.VERTICAL && (position + 1) % spanCount == 0) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
return;
}
if(orientation == OrientationHelper.HORIZONTAL && (position + 1) % spanCount == 0) {
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
return;
}
outRect.set(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight());
}
示例3: recycleFromStart
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
private void recycleFromStart(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) {
final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
boolean changed = true;
while (helper.getChildCount() > 0 && changed) {
View child = helper.getChildAt(0);
if (child != null && orientationHelper.getDecoratedEnd(child) < line) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int position = lp.getViewPosition();
Span span = findSpan(position, child, true);
if (span != null) {
span.popStart(orientationHelper);
helper.removeChildView(child);
recycler.recycleView(child);
} else {
changed = false;
}
} else {
return;// done
}
}
}
示例4: recycleFromEnd
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
private void recycleFromEnd(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) {
final OrientationHelper orientationHelper = helper.getMainOrientationHelper();
final int childCount = helper.getChildCount();
int i;
for (i = childCount - 1; i >= 0; i--) {
View child = helper.getChildAt(i);
if (child != null && orientationHelper.getDecoratedStart(child) > line) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int position = lp.getViewPosition();
Span span = findSpan(position, child, false);
if (span != null) {
span.popEnd(orientationHelper);
helper.removeChildView(child);
recycler.recycleView(child);
}
} else {
return;// done
}
}
}
示例5: calculateDistanceToFinalSnap
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) {
int[] out = new int[2];
if (layoutManager.canScrollHorizontally()) {
out[0] = getDistance(layoutManager, targetView, OrientationHelper.createHorizontalHelper(layoutManager));
} else {
out[0] = 0;
}
if (layoutManager.canScrollVertically()) {
out[1] = getDistance(layoutManager, targetView, OrientationHelper.createVerticalHelper(layoutManager));
} else {
out[1] = 0;
}
return out;
}
示例6: onCreateView
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
@CallSuper
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view;
if (orientation() == OrientationHelper.VERTICAL) {
view = inflater.inflate(R.layout.vertical_fragment_brick, container, false);
} else {
view = inflater.inflate(R.layout.horizontal_fragment_brick, container, false);
}
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setBackgroundColor(recyclerViewBackground);
((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
dataManager.setRecyclerView(getContext(), recyclerView, orientation(), reverse(), view);
return view;
}
示例7: onCreate
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_list);
ButterKnife.bind(this);
activityComponent().inject(this);
mRecyclerView.setAdapter(adapter);
int showListCountSpan = getResources().getInteger(R.integer.show_list_count_span);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(showListCountSpan, OrientationHelper.VERTICAL));
mPresenter.attachView(this);
mPresenter.load(savedInstanceState == null);
adapter.setItemClickListener((view, item) ->
startActivity(ShowDetailsActivity.getOpenIntent(this, item.getId())));
}
示例8: draw
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
private void draw(Canvas c, RecyclerView parent) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if ((layoutManager instanceof LinearLayoutManager)) {
LinearLayoutManager manager = (LinearLayoutManager) layoutManager;
if (manager.getOrientation() == OrientationHelper.VERTICAL)
drawVerticalOrientationDividers(c, parent, manager);
else
drawHorizontalOrientationDividers(c, parent, manager);
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
Log.e(getClass().getSimpleName(), "Will soon support this feature !!");
} else {
throw new UnsupportedOperationException(getClass().getSimpleName() +
" can only be used in the RecyclerView which use GridLayoutManager" +
" or LinearLayoutManager or StaggeredGridLayoutManager");
}
}
示例9: scrollToRightPositionWhenItemChanged
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
/**
* 当item位置变换,滚动recycler到正确的位置
* TODO: 2017/2/21 0021 整理更优雅的写法 还有scrollToPosition(0)是否必要?
*/
private void scrollToRightPositionWhenItemChanged(RecyclerView recyclerView, View itemView, int itemPos) {
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof ItemTouchHelper.ViewDropHandler) {
OrientationHelper helper = OrientationHelper.createVerticalHelper(layoutManager);
int start = helper.getDecoratedStart(itemView);
int end = helper.getDecoratedEnd(itemView);
((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(
itemPos, lastItemPos > itemPos ? start : end - itemViewHeight);
// System.out.println(lastItemPos + "-" + childPos + "OrientationHelperOrientationHelper:"
// + height + "==" + itemViewHeight + "=||=" + start + "===" + end + "||||||" + myStart + "===" + itemTargetView.getHeight() );
}
if (lastItemPos == 0 || itemPos == 0) {
recyclerView.scrollToPosition(0);
}
}
示例10: onScrollStateChanged
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
//Fix for bug with bottom selection bar and different month item height in horizontal mode (different count of weeks)
View view = rvMonths.getLayoutManager().findViewByPosition(getFirstVisiblePosition(rvMonths.getLayoutManager()));
if (view != null) {
view.requestLayout();
}
if (getCalendarOrientation() == OrientationHelper.HORIZONTAL) {
multipleSelectionBarAdapter.notifyDataSetChanged();
//Hide navigation buttons
boolean show = newState != RecyclerView.SCROLL_STATE_DRAGGING;
ivPrevious.setVisibility(show ? View.VISIBLE : View.GONE);
ivNext.setVisibility(show ? View.VISIBLE : View.GONE);
}
super.onScrollStateChanged(recyclerView, newState);
}
示例11: onViewCreated
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
int orientation = OrientationHelper.VERTICAL;
boolean reverseLayout = false;
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), orientation, reverseLayout);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
mAdapter = new SongsAdapter();
mRecyclerView.setAdapter(mAdapter);
// hide whole interface until the fragment is connected with the service
hideContent();
}
示例12: distanceToEnd
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
private int distanceToEnd(View targetView, OrientationHelper helper, boolean fromStart) {
if (mIsRtlHorizontal && !fromStart) {
return distanceToStart(targetView, helper, true);
}
return helper.getDecoratedEnd(targetView) - helper.getEndAfterPadding();
}
示例13: getItemOffsets
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int orientation = 0;
int headerCount = 0,footerCount = 0;
if (parent.getAdapter() instanceof RecyclerArrayAdapter){
headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
}
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager){
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof GridLayoutManager){
orientation = ((GridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof LinearLayoutManager){
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){
if (orientation == OrientationHelper.VERTICAL){
outRect.bottom = mHeight;
}else {
outRect.right = mHeight;
}
}
}
示例14: doBusiness
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
protected void doBusiness() {
toolbarTitle.setText("新生攻略");
recyclerView.setLayoutManager(new LinearLayoutManager(context, OrientationHelper.VERTICAL, false));
adapter = new FreshmanGuideAdapter(context, dataList);
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DividerItemDecoration(context, OrientationHelper.VERTICAL));
freshmanGuidePresenter = new FreshmanGuidePresenter(this, this);
freshmanGuidePresenter.showGuideList();
}
示例15: onCreate
import android.support.v7.widget.OrientationHelper; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_recyclerview);
// Workaround for dash path effect
// https://code.google.com/p/android/issues/detail?id=29944
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
recyclerView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
SimpleAdapter adapter = new SimpleAdapter(this);
LinearLayoutManager manager = new LinearLayoutManager(this);
manager.setOrientation(OrientationHelper.VERTICAL);
recyclerView.setLayoutManager(manager);
recyclerView.setAdapter(adapter);
Paint paint = new Paint();
paint.setStrokeWidth(5);
paint.setColor(Color.BLUE);
paint.setAntiAlias(true);
paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0));
recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)
.paint(paint)
.showLastDivider()
.build());
}