Java Code Examples for androidx.recyclerview.widget.RecyclerView#setLayoutParams()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#setLayoutParams() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwipeOpenItemTouchHelperTestActivity.java From SwipeOpenItemTouchHelper with Apache License 2.0 | 6 votes |
@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); } }
Example 2
Source File: TransitionMusicLibraryDemoFragment.java From material-components-android with Apache License 2.0 | 6 votes |
private RecyclerView createRecyclerView(boolean listTypeGrid) { Context context = requireContext(); RecyclerView recyclerView = new RecyclerView(context); recyclerView.setLayoutParams( new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); int verticalPadding = context.getResources().getDimensionPixelSize(R.dimen.album_list_padding_vertical); recyclerView.setPadding(0, verticalPadding, 0, verticalPadding); recyclerView.setClipToPadding(false); if (listTypeGrid) { recyclerView.setLayoutManager(new GridLayoutManager(context, GRID_SPAN_COUNT)); } else { recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.addItemDecoration( new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); } return recyclerView; }
Example 3
Source File: ReactWithAnyEmojiAdapter.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { recyclerView.setNestedScrollingEnabled(false); ViewGroup.LayoutParams params = recyclerView.getLayoutParams(); params.height = (int) (recyclerView.getResources().getDisplayMetrics().heightPixels * 0.80); recyclerView.setLayoutParams(params); recyclerView.setHasFixedSize(true); }
Example 4
Source File: AddressDialog.java From AndroidProject with Apache License 2.0 | 5 votes |
ViewHolder() { super(new RecyclerView(getContext())); RecyclerView recyclerView = (RecyclerView) getItemView(); recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mAdapter = new AddressAdapter(getContext()); mAdapter.setOnItemClickListener(this); recyclerView.setAdapter(mAdapter); }
Example 5
Source File: PictureMultiCuttingActivity.java From Matisse-Kotlin with Apache License 2.0 | 5 votes |
/** * 动态添加多图裁剪底部预览图片列表 */ 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); }
Example 6
Source File: PBaseLoaderFragment.java From YImagePicker with Apache License 2.0 | 5 votes |
/** * 设置文件夹列表的高度 * * @param mFolderListRecyclerView 文件夹列表 * @param mImageSetMask 文件夹列表的灰色透明蒙层 * @param isCrop 是否是小红书样式 */ protected void setFolderListHeight(RecyclerView mFolderListRecyclerView, View mImageSetMask, boolean isCrop) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mFolderListRecyclerView.getLayoutParams(); RelativeLayout.LayoutParams maskParams = (RelativeLayout.LayoutParams) mImageSetMask.getLayoutParams(); PickerUiConfig uiConfig = getUiConfig(); int height = uiConfig.getFolderListOpenMaxMargin(); if (uiConfig.getFolderListOpenDirection() == PickerUiConfig.DIRECTION_BOTTOM) { params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); if (isCrop) { params.bottomMargin = bottomBar != null ? bottomBar.getViewHeight() : 0; params.topMargin = (titleBar != null ? titleBar.getViewHeight() : 0) + height; maskParams.topMargin = (titleBar != null ? titleBar.getViewHeight() : 0); maskParams.bottomMargin = bottomBar != null ? bottomBar.getViewHeight() : 0; } else { params.bottomMargin = 0; params.topMargin = height; } } else { params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); if (isCrop) { params.bottomMargin = height + (bottomBar != null ? bottomBar.getViewHeight() : 0); params.topMargin = titleBar != null ? titleBar.getViewHeight() : 0; maskParams.topMargin = (titleBar != null ? titleBar.getViewHeight() : 0); maskParams.bottomMargin = bottomBar != null ? bottomBar.getViewHeight() : 0; } else { params.bottomMargin = height; params.topMargin = 0; } } mFolderListRecyclerView.setLayoutParams(params); mImageSetMask.setLayoutParams(maskParams); }
Example 7
Source File: RecyclerViewHeader.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
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); } } }
Example 8
Source File: EmoticonParentAdapter.java From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { RecyclerView recyclerView = new RecyclerView(mContext); recyclerView.setLayoutManager(new GridLayoutManager(mContext, COLUMN_COUNT)); recyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); EmoticonChildAdapter adapter = new EmoticonChildAdapter(mContext, mHeight); adapter.setData(EmoticonUtils.EMOTICON_LABEL[position][0], EmoticonUtils.EMOTICON_URL[position]); recyclerView.setAdapter(adapter); container.addView(recyclerView); return recyclerView; }
Example 9
Source File: ExplodeAndEpicenterExample.java From Transitions-Everywhere with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRecyclerView = new RecyclerView(container.getContext()); mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mRecyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 4)); mRecyclerView.setAdapter(new Adapter()); return mRecyclerView; }
Example 10
Source File: PictureMultiCuttingActivity.java From PictureSelector with Apache License 2.0 | 4 votes |
/** * 动态添加多图裁剪底部预览图片列表 */ 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); }