Java Code Examples for android.support.v7.widget.RecyclerView#setPadding()
The following examples show how to use
android.support.v7.widget.RecyclerView#setPadding() .
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: ViewHelper.java From FABRevealMenu-master with Apache License 2.0 | 7 votes |
public RecyclerView generateMenuView(boolean enableNestedScrolling) { //Create menu view RecyclerView mMenuView = new RecyclerView(mContext); mMenuView.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER); mMenuView.setBackgroundColor(Color.TRANSPARENT); mMenuView.setLayoutParams(matchParams); final int padding = dpToPx(mContext, 10); mMenuView.setPadding(padding, padding, padding, padding); mMenuView.setNestedScrollingEnabled(enableNestedScrolling); return mMenuView; }
Example 2
Source File: BookcaseFragment.java From FriendBook with GNU General Public License v3.0 | 6 votes |
@Override public void setRecyclerView(RecyclerView recyclerView) { recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3)); recyclerView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); ((SimpleItemAnimator)recyclerView.getItemAnimator()).setSupportsChangeAnimations(false); int i = getResources().getDisplayMetrics().widthPixels; int y = DensityUtil.dp2px(getContext(), 90); int p = DensityUtil.dp2px(getContext(), 15); int padding = (3 * y + 2 * 3 * p + 2 * p - i) / (2 * 3); recyclerView.setPadding( padding, DensityUtil.dp2px(getContext(), 8), padding, DensityUtil.dp2px(getContext(), 8) ); }
Example 3
Source File: RecyclerViewFragment.java From kernel_adiutor with Apache License 2.0 | 6 votes |
public void setOnScrollListener(RecyclerView recyclerView) { if (recyclerView != null) { int paddingBottom = recyclerView.getPaddingBottom() + getResources().getDimensionPixelSize(R.dimen.basecard_padding); if (applyOnBootLayout != null) { recyclerView.setPadding(0, applyOnBootLayout.getHeight(), 0, firstOpening ? paddingBottom : recyclerView.getPaddingBottom()); resetTranslations(); if (!Utils.isTV(getActivity())) recyclerView.addOnScrollListener(onScrollListener = new CustomScrollListener()); } else recyclerView.setPadding(0, 0, 0, firstOpening ? paddingBottom : recyclerView.getPaddingBottom()); recyclerView.setClipToPadding(false); } }
Example 4
Source File: TileContentFragment.java From android-design-library with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RecyclerView recyclerView = (RecyclerView) inflater.inflate( R.layout.recycler_view, container, false); ContentAdapter adapter = new ContentAdapter(recyclerView.getContext()); recyclerView.setAdapter(adapter); recyclerView.setHasFixedSize(true); // Set padding for Tiles int tilePadding = getResources().getDimensionPixelSize(R.dimen.tile_padding); recyclerView.setPadding(tilePadding, tilePadding, tilePadding, tilePadding); recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); return recyclerView; }
Example 5
Source File: ColorActivity.java From GreatFit with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RecyclerView root = new RecyclerView(this); //Add header to a list of settings List<BaseSetting> settings = new ArrayList<>(); settings.add(new HeaderSetting(getString(R.string.set_color))); //Setup items for each day String[] colors = getResources().getStringArray(R.array.colors); String[] colorCodes = getResources().getStringArray(R.array.color_codes); final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE); int x = 0; int current = sharedPreferences.getInt("color", -1); for(String color : colors){ //Each item needs a Setting final int finalX = x; settings.add(new IconSetting( (current==x)?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), color, null, new View.OnClickListener() { @Override public void onClick(View view) { sharedPreferences.edit().putInt("color", finalX).apply(); ColorActivity.this.finish(); } }, Color.parseColor(colorCodes[x]))); x++; } //Setup layout root.setBackgroundResource(R.drawable.settings_background); root.setLayoutManager(new LinearLayoutManager(this)); root.setAdapter(new Adapter(this, settings)); root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large)); root.setClipToPadding(false); setContentView(root); }
Example 6
Source File: ContentLoaderView.java From Sky31Radio with Apache License 2.0 | 5 votes |
private void initViews(){ inflate(getContext(), R.layout.merge_content_loader, this); setPadding(0, 0, 0, 0); setClickable(true); errorView = findViewById(R.id.error_view); emptyView = findViewById(R.id.empty_view); loadingView = findViewById(R.id.loading_view); refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresher); recyclerView = (RecyclerView) findViewById(R.id.recycler); errorRetryBtn = (Button) findViewById(R.id.btn_error_retry); errorMessageTV = (TextView) findViewById(R.id.error_message); emptyRetryBtn = (Button) findViewById(R.id.btn_empty_retry); emptyMessageTV = (TextView) findViewById(R.id.empty_message); errorRetryBtn.setOnClickListener(this); emptyRetryBtn.setOnClickListener(this); contentView = refreshLayout; refreshLayout.setEnabled(false); refreshLayout.setColorSchemeResources( android.R.color.holo_blue_light, android.R.color.holo_purple, android.R.color.holo_green_light, android.R.color.holo_red_light, android.R.color.holo_orange_light); refreshLayout.setOnRefreshListener(this); recyclerView.setOnScrollListener(mRecyclerScrollListener); if(padding!=-1){ recyclerView.setPadding(padding, padding, padding,padding); }else{ recyclerView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } recyclerView.setClipToPadding(clipToPadding); setDisplayState(STATE_LOADING); }
Example 7
Source File: GridSpacingItemDecoration.java From SimpleVideoEdit with Apache License 2.0 | 5 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { if (parent.getPaddingLeft() != halfSpace) { parent.setPadding(halfSpace, halfSpace, halfSpace, halfSpace); parent.setClipToPadding(false); } outRect.top = halfSpace; outRect.bottom = halfSpace; outRect.left = halfSpace; outRect.right = halfSpace; }
Example 8
Source File: BaseLayoutMargin.java From recycler-view-margin-decoration with Apache License 2.0 | 5 votes |
void setPadding( RecyclerView rv, @Px int top, @Px int bottom, @Px int left, @Px int right ){ rv.setClipToPadding( false ); rv.setScrollBarStyle( SCROLLBARS_OUTSIDE_OVERLAY ); rv.setPadding( left, top, right, bottom ); }
Example 9
Source File: AbsLibraryPagerRecyclerViewCustomGridSizeFragment.java From Orin with GNU General Public License v3.0 | 5 votes |
protected void applyRecyclerViewPaddingForLayoutRes(@NonNull RecyclerView recyclerView, @LayoutRes int res) { int padding; if (res == R.layout.item_grid) { padding = (int) (getResources().getDisplayMetrics().density * 2); } else { padding = 0; } recyclerView.setPadding(padding, padding, padding, padding); }
Example 10
Source File: VerticalStepperView.java From ShareBox with Apache License 2.0 | 5 votes |
private void prepareListView(Context context) { mListView = new RecyclerView(context); mAdapter = new ItemAdapter(); mListView.setClipToPadding(false); mListView.setPadding(0, getResources().getDimensionPixelSize(R.dimen.stepper_margin_top), 0, 0); mListView.addItemDecoration(new VerticalSpaceItemDecoration( getResources().getDimensionPixelSize(R.dimen.vertical_stepper_item_space_height))); mListView.setLayoutManager(new LinearLayoutManager(context)); mListView.setAdapter(mAdapter); addView(mListView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); }
Example 11
Source File: TileContentFragment.java From android-design-library with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RecyclerView recyclerView = (RecyclerView) inflater.inflate( R.layout.recycler_view, container, false); ContentAdapter adapter = new ContentAdapter(recyclerView.getContext()); recyclerView.setAdapter(adapter); recyclerView.setHasFixedSize(true); // Set padding for Tiles int tilePadding = getResources().getDimensionPixelSize(R.dimen.tile_padding); recyclerView.setPadding(tilePadding, tilePadding, tilePadding, tilePadding); recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); return recyclerView; }
Example 12
Source File: DesktopOptionView.java From openlauncher with Apache License 2.0 | 5 votes |
private RecyclerView createRecyclerView(FastAdapter adapter, int gravity, int paddingHorizontal) { RecyclerView actionRecyclerView = new RecyclerView(getContext()); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); actionRecyclerView.setClipToPadding(false); actionRecyclerView.setPadding(paddingHorizontal, 0, paddingHorizontal, 0); actionRecyclerView.setLayoutManager(linearLayoutManager); actionRecyclerView.setAdapter(adapter); actionRecyclerView.setOverScrollMode(OVER_SCROLL_ALWAYS); LayoutParams actionRecyclerViewLP = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); actionRecyclerViewLP.gravity = gravity; addView(actionRecyclerView, actionRecyclerViewLP); return actionRecyclerView; }
Example 13
Source File: BaseSettingFragment.java From ForPDA with GNU General Public License v3.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View rootView = getView(); if (rootView != null) { RecyclerView list = (RecyclerView) rootView.findViewById(android.support.v7.preference.R.id.list); if (list != null) { list.setPadding(0, 0, 0, 0); } } setDividerHeight(0); }
Example 14
Source File: TileContentFragment.java From android-design-library with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RecyclerView recyclerView = (RecyclerView) inflater.inflate( R.layout.recycler_view, container, false); ContentAdapter adapter = new ContentAdapter(recyclerView.getContext()); recyclerView.setAdapter(adapter); recyclerView.setHasFixedSize(true); // Set padding for Tiles int tilePadding = getResources().getDimensionPixelSize(R.dimen.tile_padding); recyclerView.setPadding(tilePadding, tilePadding, tilePadding, tilePadding); recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); return recyclerView; }
Example 15
Source File: SpacesItemDecoration.java From Android-Pull-To-Refresh with Apache License 2.0 | 4 votes |
/** * only setPadding * @param recyclerView RecyclerView * @param space px */ public SpacesItemDecoration(RecyclerView recyclerView, int space) { this(space); int halfSpace = space / 2; recyclerView.setPadding(halfSpace, halfSpace, halfSpace, halfSpace); }
Example 16
Source File: EasyRecyclerView.java From BookReader with Apache License 2.0 | 4 votes |
/** * Implement this method to customize the AbsListView */ protected void initRecyclerView(View view) { mRecycler = (RecyclerView) view.findViewById(android.R.id.list); tipView = (TextView) view.findViewById(R.id.tvTip); setItemAnimator(null); if (mRecycler != null) { mRecycler.setHasFixedSize(true); mRecycler.setClipToPadding(mClipToPadding); mInternalOnScrollListener = new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (mExternalOnScrollListener != null) mExternalOnScrollListener.onScrolled(recyclerView, dx, dy); } @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (mExternalOnScrollListener != null) mExternalOnScrollListener.onScrollStateChanged(recyclerView, newState); } }; mRecycler.addOnScrollListener(mInternalOnScrollListener); if (mPadding != -1.0f) { mRecycler.setPadding(mPadding, mPadding, mPadding, mPadding); } else { mRecycler.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom); } if (mScrollbarStyle != -1) { mRecycler.setScrollBarStyle(mScrollbarStyle); } switch (mScrollbar) { case 0: setVerticalScrollBarEnabled(false); break; case 1: setHorizontalScrollBarEnabled(false); break; case 2: setVerticalScrollBarEnabled(false); setHorizontalScrollBarEnabled(false); break; } } }
Example 17
Source File: MiniDrawer.java From MaterialDrawer-Xamarin with Apache License 2.0 | 4 votes |
/** * build the MiniDrawer * * @param ctx * @return */ public View build(Context ctx) { mContainer = new LinearLayout(ctx); if (mInnerShadow) { if (!mInRTL) { mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left); } else { mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right); } } //create and append recyclerView mRecyclerView = new RecyclerView(ctx); mContainer.addView(mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); //set the itemAnimator mRecyclerView.setItemAnimator(new DefaultItemAnimator()); //some style improvements on older devices mRecyclerView.setFadingEdgeLength(0); //set the drawing cache background to the same color as the slider to improve performance //mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity, R.attr.material_drawer_background, R.color.material_drawer_background)); mRecyclerView.setClipToPadding(false); //additional stuff mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx)); //adapter mDrawerAdapter = new DrawerAdapter(); mRecyclerView.setAdapter(mDrawerAdapter); //if the activity with the drawer should be fullscreen add the padding for the statusbar if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) { mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), UIUtils.getStatusBarHeight(ctx), mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom()); } //if the activity with the drawer should be fullscreen add the padding for the navigationBar if (mDrawer != null && mDrawer.mDrawerBuilder != null && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentNavigationBar)) { mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(), mRecyclerView.getPaddingRight(), UIUtils.getNavigationBarHeight(ctx)); } //set the adapter with the items createItems(); return mContainer; }
Example 18
Source File: WidgetsActivity.java From GreatFit with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RecyclerView root = new RecyclerView(this); //Add header to a list of settings List<BaseSetting> settings = new ArrayList<>(); settings.add(new HeaderSetting(getString(R.string.set_elements))); //Setup items for each day String[] elements = getResources().getStringArray(R.array.supported_widgets); final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE); // Get Widgets String widgetsAsText = sharedPreferences.getString("widgets", null); String text = widgetsAsText.replaceAll("(\\[|\\]| )",""); // Replace "[", "]" and "spaces" List <String> widgets_list = Arrays.asList(text.split(",")); int current = sharedPreferences.getInt("temp_widget", 0); String currentAsText = widgets_list.get(current); for(String element : elements){ // Go to next if already a widget if(widgets_list.indexOf(element)>=0 && !element.equals(currentAsText) && !element.equals("none")){ continue; } // Create the setting widgets_list.set(current,element); final String finalWidgets = widgets_list.toString(); settings.add(new IconSetting( (element.equals(currentAsText))?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), prepareTitle(element), prepareSubtitle(element), new View.OnClickListener() { @Override public void onClick(View view) { sharedPreferences.edit().putString("widgets", finalWidgets).apply(); WidgetsActivity.this.finish(); } }, null)); } //Setup layout root.setBackgroundResource(R.drawable.settings_background); root.setLayoutManager(new LinearLayoutManager(this)); root.setAdapter(new Adapter(this, settings)); root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large)); root.setClipToPadding(false); setContentView(root); }
Example 19
Source File: EasyRecyclerView.java From fangzhuishushenqi with Apache License 2.0 | 4 votes |
/** * Implement this method to customize the AbsListView */ protected void initRecyclerView(View view) { mRecycler = (RecyclerView) view.findViewById(android.R.id.list); tipView = (TextView) view.findViewById(R.id.tvTip); setItemAnimator(null); if (mRecycler != null) { mRecycler.setHasFixedSize(true); mRecycler.setClipToPadding(mClipToPadding); mInternalOnScrollListener = new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (mExternalOnScrollListener != null) mExternalOnScrollListener.onScrolled(recyclerView, dx, dy); } @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (mExternalOnScrollListener != null) mExternalOnScrollListener.onScrollStateChanged(recyclerView, newState); } }; mRecycler.addOnScrollListener(mInternalOnScrollListener); if (mPadding != -1.0f) { mRecycler.setPadding(mPadding, mPadding, mPadding, mPadding); } else { mRecycler.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom); } if (mScrollbarStyle != -1) { mRecycler.setScrollBarStyle(mScrollbarStyle); } switch (mScrollbar) { case 0: setVerticalScrollBarEnabled(false); break; case 1: setHorizontalScrollBarEnabled(false); break; case 2: setVerticalScrollBarEnabled(false); setHorizontalScrollBarEnabled(false); break; } } }
Example 20
Source File: ProgressWidgetsActivity.java From GreatFit with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RecyclerView root = new RecyclerView(this); //Add header to a list of settings List<BaseSetting> settings = new ArrayList<>(); settings.add(new HeaderSetting(getString(R.string.set_progress_bar))); //Setup items for each day String[] elements = getResources().getStringArray(R.array.supported_progress_elements); final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE); // Get Widgets String widgetsAsText = sharedPreferences.getString("progress_bars", null); String text = widgetsAsText.replaceAll("(\\[|\\]| )",""); // Replace "[", "]" and "spaces" List <String> widgets_list = Arrays.asList(text.split(",")); int current = sharedPreferences.getInt("temp_progress_bars", 0); String currentAsText = widgets_list.get(current); for(String element : elements){ // Go to next if already a widget if(widgets_list.indexOf(element)>=0 && !element.equals(currentAsText) && !element.equals("none")){ continue; } // Create the setting widgets_list.set(current,element); final String finalWidgets = widgets_list.toString(); settings.add(new IconSetting( (element.equals(currentAsText))?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), prepareTitle(element), prepareSubtitle(element), new View.OnClickListener() { @Override public void onClick(View view) { sharedPreferences.edit().putString("progress_bars", finalWidgets).apply(); ProgressWidgetsActivity.this.finish(); } }, null)); } //Setup layout root.setBackgroundResource(R.drawable.settings_background); root.setLayoutManager(new LinearLayoutManager(this)); root.setAdapter(new Adapter(this, settings)); root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large)); root.setClipToPadding(false); setContentView(root); }