androidx.recyclerview.widget.RecyclerView#setId ( )源码实例Demo

下面列出了androidx.recyclerview.widget.RecyclerView#setId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  RecyclerView recyclerView = new RecyclerView(this);
  recyclerView.setId(R.id.test_recycler);
  recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
      ViewGroup.LayoutParams.MATCH_PARENT));
  recyclerView.setLayoutManager(new LinearLayoutManager(this));
  recyclerView.setAdapter(new TestAdapter(this));
  setContentView(recyclerView);

  helper = new SwipeOpenItemTouchHelper(
      new SwipeOpenItemTouchHelper.SimpleCallback(
          SwipeOpenItemTouchHelper.START | SwipeOpenItemTouchHelper.END));
  helper.attachToRecyclerView(recyclerView);

  if (savedInstanceState != null) {
    helper.restoreInstanceState(savedInstanceState);
  }
}
 
/**
 * 动态添加多图裁剪底部预览图片列表
 */
private void addPhotoRecyclerView() {
    mRecyclerView = new RecyclerView(this);
    mRecyclerView.setId(R.id.id_recycler);
    mRecyclerView.setBackgroundColor(ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
    RelativeLayout.LayoutParams lp =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dip2px(80));
    mRecyclerView.setLayoutParams(lp);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    resetCutDataStatus();
    list.get(cutIndex).setCut(true);
    adapter = new PicturePhotoGalleryAdapter(this, list);
    mRecyclerView.setAdapter(adapter);
    adapter.setOnItemClickListener((position, view) -> {
        if (cutIndex == position) {
            return;
        }
        cutIndex = position;
        resetCutData();
    });

    uCropMultiplePhotoBox.addView(mRecyclerView);
    changeLayoutParams();
    FrameLayout uCropFrame = findViewById(R.id.ucrop_frame);
    ((RelativeLayout.LayoutParams) uCropFrame.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.id_recycler);
}
 
源代码3 项目: litho   文件: RecyclerSpec.java
@OnUnmount
static void onUnmount(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true) SnapHelper snapHelper) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  recyclerView.setId(RecyclerSpec.recyclerViewId);

  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(
        DEFAULT_REFRESH_SPINNER_BACKGROUND_COLOR);
  }

  if (itemDecoration != null) {
    recyclerView.removeItemDecoration(itemDecoration);
  }

  binder.unmount(recyclerView);

  if (snapHelper != null) {
    snapHelper.attachToRecyclerView(null);
  }

  sectionsRecycler.resetItemAnimator();
}
 
@Implementation
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RecyclerView recyclerView = new RecyclerView(container.getContext());
    recyclerView.setId(android.R.id.list_container);
    ReflectionHelpers.setField(realObject, "mList", recyclerView);
    return recyclerView;
}
 
源代码5 项目: HaoReader   文件: FastScrollView.java
private void layout(Context context, AttributeSet attrs) {
    fastScroller = new FastScroller(context, attrs);
    fastScroller.setId(R.id.fast_scroller);
    recyclerView = new RecyclerView(context, attrs);
    recyclerView.setId(R.id.recycler_view);
}
 
源代码6 项目: litho   文件: RecyclerSpec.java
@OnMount
static void onMount(
    ComponentContext c,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) boolean hasFixedSize,
    @Prop(optional = true) boolean clipToPadding,
    @Prop(optional = true) int leftPadding,
    @Prop(optional = true) int rightPadding,
    @Prop(optional = true) int topPadding,
    @Prop(optional = true) int bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) int refreshProgressBarColor,
    @Prop(optional = true) boolean clipChildren,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) int scrollBarStyle,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true) boolean horizontalFadingEdgeEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @IdRes int recyclerViewId,
    @Prop(optional = true) int overScrollMode,
    @Prop(optional = true, isCommonProp = true) CharSequence contentDescription,
    @Prop(optional = true) ItemAnimator itemAnimator) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout");
  }
  recyclerView.setContentDescription(contentDescription);
  recyclerView.setHasFixedSize(hasFixedSize);
  recyclerView.setClipToPadding(clipToPadding);
  sectionsRecycler.setClipToPadding(clipToPadding);
  ViewCompat.setPaddingRelative(
      recyclerView, leftPadding, topPadding, rightPadding, bottomPadding);
  recyclerView.setClipChildren(clipChildren);
  sectionsRecycler.setClipChildren(clipChildren);
  recyclerView.setNestedScrollingEnabled(nestedScrollingEnabled);
  sectionsRecycler.setNestedScrollingEnabled(nestedScrollingEnabled);
  recyclerView.setScrollBarStyle(scrollBarStyle);
  recyclerView.setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled);
  recyclerView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  recyclerView.setFadingEdgeLength(fadingEdgeLength);
  // TODO (t14949498) determine if this is necessary
  recyclerView.setId(recyclerViewId);
  recyclerView.setOverScrollMode(overScrollMode);
  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(refreshProgressBarBackgroundColor);
  }
  sectionsRecycler.setColorSchemeColors(refreshProgressBarColor);

  if (itemDecoration != null) {
    recyclerView.addItemDecoration(itemDecoration);
  }

  sectionsRecycler.setItemAnimator(
      itemAnimator != RecyclerSpec.itemAnimator ? itemAnimator : new NoUpdateItemAnimator());

  binder.mount(recyclerView);
}
 
/**
 * 动态添加多图裁剪底部预览图片列表
 */
private void addPhotoRecyclerView() {
    boolean isMultipleSkipCrop = getIntent().getBooleanExtra(UCrop.Options.EXTRA_SKIP_MULTIPLE_CROP, true);
    mRecyclerView = new RecyclerView(this);
    mRecyclerView.setId(R.id.id_recycler);
    mRecyclerView.setBackgroundColor(ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
    RelativeLayout.LayoutParams lp =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                    ScreenUtils.dip2px(this, 80));
    mRecyclerView.setLayoutParams(lp);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    if (isAnimation) {
        LayoutAnimationController animation = AnimationUtils
                .loadLayoutAnimation(getApplicationContext(), R.anim.ucrop_layout_animation_fall_down);
        mRecyclerView.setLayoutAnimation(animation);
    }
    mRecyclerView.setLayoutManager(mLayoutManager);
    // 解决调用 notifyItemChanged 闪烁问题,取消默认动画
    ((SimpleItemAnimator) mRecyclerView.getItemAnimator())
            .setSupportsChangeAnimations(false);
    resetCutDataStatus();
    list.get(cutIndex).setCut(true);
    mAdapter = new PicturePhotoGalleryAdapter(this, list);
    mRecyclerView.setAdapter(mAdapter);
    if (isMultipleSkipCrop) {
        mAdapter.setOnItemClickListener(new PicturePhotoGalleryAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, View view) {
                CutInfo cutInfo = list.get(position);
                if (MimeType.isHasVideo(cutInfo.getMimeType())) {
                    return;
                }
                if (cutIndex == position) {
                    return;
                }
                resetLastCropStatus();
                cutIndex = position;
                oldCutIndex = cutIndex;
                resetCutData();
            }
        });
    }
    uCropPhotoBox.addView(mRecyclerView);
    changeLayoutParams(mShowBottomControls);

    // 裁剪框居于RecyclerView之上
    FrameLayout uCropFrame = findViewById(R.id.ucrop_frame);
    ((RelativeLayout.LayoutParams) uCropFrame.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.id_recycler);

    // RecyclerView居于BottomControls之上
    ((RelativeLayout.LayoutParams) mRecyclerView.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.controls_wrapper);
}