Java Code Examples for android.support.v7.widget.LinearLayoutManager#VERTICAL
The following examples show how to use
android.support.v7.widget.LinearLayoutManager#VERTICAL .
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: DividerItemDecoration.java From AndroidSchool with Apache License 2.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); if (mDivider == null) { return; } int position = parent.getChildAdapterPosition(view); if (position == RecyclerView.NO_POSITION || (position == 0)) { return; } if (mOrientation == -1) { getOrientation(parent); } if (mOrientation == LinearLayoutManager.VERTICAL) { outRect.top = mDivider.getIntrinsicHeight(); } else { outRect.left = mDivider.getIntrinsicWidth(); } }
Example 2
Source File: DivideItemDecoration.java From GroupIndexLib with Apache License 2.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); if (Utils.listIsEmpty(tags)) { return; } RecyclerView.LayoutManager manager = parent.getLayoutManager(); //只处理线性垂直类型的列表 if ((manager instanceof LinearLayoutManager) && LinearLayoutManager.VERTICAL != ((LinearLayoutManager) manager).getOrientation()) { return; } int position = parent.getChildAdapterPosition(view); if (!Utils.listIsEmpty(tags) && (position + 1) < tags.size() && tags.get(position).equals(tags.get(position + 1))) { //当前ItemView的data的tag和下一个ItemView的不相等,则为当前ItemView设置bottom 偏移量 outRect.set(0, 0, 0, divideHeight); } }
Example 3
Source File: RecycleViewActivity.java From TraceByAmap with MIT License | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map_recycleview); mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); list = getBaseEntities(); mAdapter = new MyRecycleViewAdapter(list); // recyclerView = findViewById(R.id.recycleview); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setAdapter(mAdapter); new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } handler.sendEmptyMessage(0); } }).start(); }
Example 4
Source File: KyRecyclerViewDivider.java From BitkyShop with MIT License | 5 votes |
/** * 默认分割线:高度为2px,颜色为灰色 * * @param orientation 列表方向 */ public KyRecyclerViewDivider(Context context, int orientation) { if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) { throw new IllegalArgumentException("请输入正确的参数!"); } mOrientation = orientation; final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); }
Example 5
Source File: RecyclerFragment.java From ListItemFold with MIT License | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_item_list, container, false); mAdapter = new RecyclerDataAdapter(getActivity()); mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mAdapter); mAdapter.setOnItemClick(this); DetailAnimViewGroup wrapper = new DetailAnimViewGroup(inflater.getContext(), view, 0); loadData(); return wrapper; }
Example 6
Source File: HeaderViewCache.java From IndexRecyclerView with Apache License 2.0 | 5 votes |
@Override public View getHeader(RecyclerView parent, int position) { long headerId = mAdapter.getHeaderId(position); View header = mHeaderViews.get(headerId); if (header == null) { //TODO - recycle views RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent); mAdapter.onBindHeaderViewHolder(viewHolder, position); header = viewHolder.itemView; if (header.getLayoutParams() == null) { header.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } int widthSpec; int heightSpec; if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); } else { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY); } int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); header.measure(childWidth, childHeight); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); mHeaderViews.put(headerId, header); } return header; }
Example 7
Source File: DividerItemDecoration.java From AndroidSchool with Apache License 2.0 | 5 votes |
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { if (mDivider == null) { super.onDrawOver(c, parent, state); return; } // Initialization needed to avoid compiler warning int left = 0, right = 0, top = 0, bottom = 0, size; int orientation = mOrientation != -1 ? mOrientation : getOrientation(parent); int childCount = parent.getChildCount(); if (orientation == LinearLayoutManager.VERTICAL) { size = mDivider.getIntrinsicHeight(); left = parent.getPaddingLeft(); right = parent.getWidth() - parent.getPaddingRight(); } else { //horizontal size = mDivider.getIntrinsicWidth(); top = parent.getPaddingTop(); bottom = parent.getHeight() - parent.getPaddingBottom(); } for (int i = 1; i < childCount; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); if (orientation == LinearLayoutManager.VERTICAL) { top = child.getTop() - params.topMargin - size; bottom = top + size; } else { //horizontal left = child.getLeft() - params.leftMargin; right = left + size; } mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } // show last divider }
Example 8
Source File: MsgFragment.java From OpenPagerAdapter with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRvAdapter = new RvAdapter(); for (int i = 0; i < 51; i++) { MsgEntity msgEntity = new MsgEntity(); msgEntity.name = mSessionName + i; mMsgDatas.add(msgEntity); } mLinearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); mRecyclerView = view.findViewById(R.id.msg_rv); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(mLinearLayoutManager); mRecyclerView.setAdapter(mRvAdapter); }
Example 9
Source File: HeaderViewCache.java From sticky-headers-recyclerview with Apache License 2.0 | 5 votes |
@Override public View getHeader(RecyclerView parent, int position) { long headerId = mAdapter.getHeaderId(position); View header = mHeaderViews.get(headerId); if (header == null) { //TODO - recycle views RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent); mAdapter.onBindHeaderViewHolder(viewHolder, position); header = viewHolder.itemView; if (header.getLayoutParams() == null) { header.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } int widthSpec; int heightSpec; if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); } else { widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED); heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY); } int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); header.measure(childWidth, childHeight); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); mHeaderViews.put(headerId, header); } return header; }
Example 10
Source File: HeaderPositionCalculator.java From googlecalendar with Apache License 2.0 | 5 votes |
private void initDefaultHeaderOffset(Rect headerMargins, RecyclerView recyclerView, View header, View firstView, int orientation) { int translationX, translationY; mDimensionCalculator.initMargins(mTempRect1, header); ViewGroup.LayoutParams layoutParams = firstView.getLayoutParams(); int leftMargin = 0; int topMargin = 0; if (layoutParams instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams; leftMargin = marginLayoutParams.leftMargin; topMargin = marginLayoutParams.topMargin; } if (orientation == LinearLayoutManager.VERTICAL) { translationX = firstView.getLeft() - leftMargin + mTempRect1.left; int headerHeight = 0; // if (header != null && header.getTag() != null && header.getTag().equals(1)) { // headerHeight = header.getHeight(); // } translationY = Math.max( firstView.getTop()+0 - topMargin - headerHeight - mTempRect1.bottom, getListTop(recyclerView) + mTempRect1.top); } else { translationY = firstView.getTop() - topMargin + mTempRect1.top; translationX = Math.max( firstView.getLeft() - leftMargin - header.getWidth() - mTempRect1.right, getListLeft(recyclerView) + mTempRect1.left); } headerMargins.set(translationX, translationY, translationX + header.getWidth(), translationY + header.getHeight()); }
Example 11
Source File: StickyRecyclerHeadersDecoration.java From sticky-headers-recyclerview with Apache License 2.0 | 5 votes |
/** * Sets the offsets for the first item in a section to make room for the header view * * @param itemOffsets rectangle to define offsets for the item * @param header view used to calculate offset for the item * @param orientation used to calculate offset for the item */ private void setItemOffsetsForHeader(Rect itemOffsets, View header, int orientation) { mDimensionCalculator.initMargins(mTempRect, header); if (orientation == LinearLayoutManager.VERTICAL) { itemOffsets.top = header.getHeight() + mTempRect.top + mTempRect.bottom; } else { itemOffsets.left = header.getWidth() + mTempRect.left + mTempRect.right; } }
Example 12
Source File: RecycleViewDivider.java From SoloPi with Apache License 2.0 | 5 votes |
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { super.onDraw(c, parent, state); if (mOrientation == LinearLayoutManager.VERTICAL) { drawVertical(c, parent); } else { drawHorizontal(c, parent); } }
Example 13
Source File: LogFragment.java From android with GNU General Public License v3.0 | 5 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true); mRecyclerView.setLayoutManager(layoutManager); mAdapter = new LogListAdapter(getActivity(), mRecyclerView); mRecyclerView.setAdapter(mAdapter); mRecyclerView.smoothScrollToPosition(mAdapter.getItemCount() - 1); }
Example 14
Source File: ContributionsByDateListFragment.java From GitJourney with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.v(TAG, "onActivityCreated"); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(linearLayoutManager); swipeRefreshLayout.setOnRefreshListener(this); getLoaderManager().initLoader(0, null, this); }
Example 15
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); }
Example 16
Source File: MainActivity.java From sectioned-recycler-view with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initFields(); // Initialize your RecyclerView with a successor of LinearLayoutManager: RecyclerView recyclerView = findViewById(R.id.recycler_view); LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(layoutManager); recyclerView.setHasFixedSize(false); // Create SectionDataManager and set its adapter to the RecyclerView. // After that you can use SectionDataManager, that implements SectionManager interface, // to add/remove/replace sections in your RecyclerView. SectionDataManager sectionDataManager = new SectionDataManager(); RecyclerView.Adapter adapter = sectionDataManager.getAdapter(); recyclerView.setAdapter(adapter); // You can customize item swiping behaviour for each section individually. // To enable this feature, create ItemTouchHelper initialized with SectionDataManager's callback // and attach it to your RecyclerView: ItemTouchHelper.Callback callback = sectionDataManager.getSwipeCallback(); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); itemTouchHelper.attachToRecyclerView(recyclerView); // To enable displaying pinned headers, attach SectionHeaderLayout to your RecyclerView and // SectionDataManager. After this you can manage header pinned state with your adapter. // You can disable displaying pinned headers any time by calling detach(). SectionHeaderLayout sectionHeaderLayout = findViewById(R.id.section_header_layout); sectionHeaderLayout.attachTo(recyclerView, sectionDataManager); for (int i = 0; i < 12; i++) { if (i % 4 == 3) { // Adding a section without header to the end of the list, passing a SimpleSectionAdapter. sectionDataManager.addSection(new HeaderlessAdapter()); continue; } int color = colors[i / 4 % 3]; BaseAdapter sectionAdapter; if (i % 4 == 0) { sectionAdapter = new DefaultAdapter(color, sectionDataManager, true, true); } else if (i % 4 == 1) { sectionAdapter = new SimpleAdapter(color, sectionDataManager, true, true); } else { sectionAdapter = new SmartAdapter(color, sectionDataManager, true, true); } DemoSwipeCallback swipeCallback = callbacks[i / 4 % 3]; // Adding a section with header to the end of the list, passing SectionAdapter, // DemoSwipeCallback to customize swiping behavior for items in this section and // a header type, that is used to determine, that sections have the same HeaderViewHolder // for further caching and reusing. sectionDataManager.addSection(sectionAdapter, swipeCallback, sectionAdapter.type); } // When using GridLayoutManager set SpanSizeLookup as follows to display full width // section headers. It uses SectionDataManager's implementation of PositionManager // to determine whether the item at the given position is a header: // final GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); // recyclerView.setLayoutManager(gridLayoutManager); // final PositionManager posManager = sectionDataManager; // gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { // @Override // public int getSpanSize(int position) { // if (posManager.isHeader(position)) { // return gridLayoutManager.getSpanCount(); // } else { // return 1; // } // } // }); }
Example 17
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * LinearLayoutManager can support HORIZONTAL or VERTICAL orientations. The reverse layout * parameter is useful mostly for HORIZONTAL layouts that should reverse for right to left * languages. */ LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); // COMPLETED (11) Pass in 'this' as the ForecastAdapterOnClickHandler /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* Once all of our views are setup, we can load the weather data. */ loadWeatherData(); }
Example 18
Source File: VideoCommentsFragment.java From Loop with Apache License 2.0 | 4 votes |
@Override public void onViewCreated(final View view, Bundle bundle) { super.onViewCreated(view, bundle); ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(TrestleUtility.getFormattedText(getString(R.string.comments), font)); } setUpListeners(); recyclerView.setItemAnimator(new SlideInUpAnimator()); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); layoutManager.setStackFromEnd(true); // layoutManager.setReverseLayout(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setItemAnimator(new SlideInUpAnimator()); videoCommentsAdapter = new VideoCommentsAdapter(getActivity()); videoCommentsAdapter.setOnItemLongClickListener(this); // List<Comment> comments = mSale.getComments(); // if (comments != null && comments.size() > 0) { // Collections.reverse(comments); // mVideoCommentsAdapter.addAll(comments); // } recyclerView.setAdapter(videoCommentsAdapter); recyclerView.scrollToPosition(videoCommentsAdapter.getItemCount() - 1); // if (commentsCollection != null) { //// loadComments(); // // List<Comment> comments = commentsCollection.getComments(); // if (comments != null && comments.size() > 0) { // // Collections.reverse(comments); // videoCommentsAdapter.addAll(comments); // recyclerView.scrollToPosition(videoCommentsAdapter.getItemCount() - 1); //// //// mVideoCommentsAdapter.addAll(comments); // // if (comments.size() >= PAGE_SIZE) { //// mVideoCommentsAdapter.addLoading(); // } else { // isLastPage = true; // } // } // } else { // // } commentChangeObservable = RxTextView.textChanges(commentEditText); // Checks for validity of the comment input field setUpCommentSubscription(); long id = video.getId(); if (id != -1L) { loadingImageView.setVisibility(View.VISIBLE); videoId = id; Call getCommentsCall = vimeoService.getComments(videoId, sortByValue, sortOrderValue, currentPage, PAGE_SIZE); calls.add(getCommentsCall); getCommentsCall.enqueue(getCommentsFirstFetchCallback); } }
Example 19
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); getSupportActionBar().setElevation(0f); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. * * The third parameter (shouldReverseLayout) should be true if you want to reverse your * layout. Generally, this is only true with horizontal lists that need to support a * right-to-left layout. */ LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); /* setLayoutManager associates the LayoutManager we created above with our RecyclerView */ mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. * * Although passing in "this" twice may seem strange, it is actually a sign of separation * of concerns, which is best programming practice. The ForecastAdapter requires an * Android Context (which all Activities are) as well as an onClickHandler. Since our * MainActivity implements the ForecastAdapter ForecastOnClickHandler interface, "this" * is also an instance of that type of handler. */ mForecastAdapter = new ForecastAdapter(this, this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); showLoading(); /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(ID_FORECAST_LOADER, null, this); SunshineSyncUtils.initialize(this); }
Example 20
Source File: Detail.java From Cook-It-Android-XML-Template with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); rootView = (CoordinatorLayout) findViewById(R.id.rootview); setupToolbar(R.id.toolbar, "DESSERTS", android.R.color.white, android.R.color.transparent, R.drawable.ic_arrow_back); collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbarLayout.setTitleEnabled(false); recyclerView = (RecyclerView) findViewById(R.id.recyclerShopping); mAdapter = new ShoppingAdapter(generateShopping(), this); LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(mAdapter); recyclerViewPreparation = (RecyclerView) findViewById(R.id.recyclerPreparation); mAdapterPreparation = new PreparationAdapter(getBaseContext(), generatePreparation(),this); LinearLayoutManager mLayoutManagerPreparation = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); recyclerViewPreparation.setLayoutManager(mLayoutManagerPreparation); recyclerViewPreparation.setItemAnimator(new DefaultItemAnimator()); recyclerViewPreparation.setAdapter(mAdapterPreparation); recyclerViewComments = (RecyclerView) findViewById(R.id.recyclerComment); mAdapterComments = new CommentsAdapter(generateComments(), this); LinearLayoutManager mLayoutManagerComment = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); recyclerViewComments.setLayoutManager(mLayoutManagerComment); recyclerViewComments.setItemAnimator(new DefaultItemAnimator()); recyclerViewComments.setAdapter(mAdapterComments); final ImageView imageComment = (ImageView) findViewById(R.id.iv_user); Glide.with(this) .load(Uri.parse("https://randomuser.me/api/portraits/women/75.jpg")) .transform(new CircleGlide(this)) .into(imageComment); final ImageView image = (ImageView) findViewById(R.id.image); Glide.with(this).load(Uri.parse("https://images.pexels.com/photos/140831/pexels-photo-140831.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb")).into(image); }