Java Code Examples for androidx.recyclerview.widget.LinearLayoutManager#VERTICAL

The following examples show how to use androidx.recyclerview.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: RcvLinearDecoration.java    From RecyclerViewAdapter with Apache License 2.0 6 votes vote down vote up
/**
 * 自定义Drawable分割线
 *
 * @param context       上下文
 * @param drawableResId 自定义分割线drawable资源id
 * @param orientation   排列方向
 */
public RcvLinearDecoration(Context context, @DrawableRes int drawableResId, int orientation)
{
    setOrientation(orientation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        mDividerDrawable = context.getResources().getDrawable(drawableResId, null);
    } else
    {
        mDividerDrawable = context.getResources().getDrawable(drawableResId);
    }

    if (orientation == LinearLayoutManager.VERTICAL)
    {
        mDividerSize = mDividerDrawable.getIntrinsicHeight();
    } else
    {
        mDividerSize = mDividerDrawable.getIntrinsicWidth();
    }
}
 
Example 2
Source File: RecyclerViewAttacher.java    From ScrollingPagerIndicator with Apache License 2.0 6 votes vote down vote up
private int findCompletelyVisiblePosition() {
    for (int i = 0; i < recyclerView.getChildCount(); i++) {
        View child = recyclerView.getChildAt(i);

        float position = child.getX();
        int size = child.getMeasuredWidth();
        float currentStart = getCurrentFrameLeft();
        float currentEnd = getCurrentFrameRight();
        if (layoutManager.getOrientation() == LinearLayoutManager.VERTICAL) {
            position = child.getY();
            size = child.getMeasuredHeight();
            currentStart = getCurrentFrameTop();
            currentEnd = getCurrentFrameBottom();
        }

        if (position >= currentStart && position + size <= currentEnd) {
            RecyclerView.ViewHolder holder = recyclerView.findContainingViewHolder(child);
            if (holder != null && holder.getAdapterPosition() != RecyclerView.NO_POSITION) {
                return holder.getAdapterPosition();
            }
        }
    }
    return RecyclerView.NO_POSITION;
}
 
Example 3
Source File: ViewItemDecoration.java    From Carbon with Apache License 2.0 6 votes vote down vote up
private void measureAndLayout(androidx.recyclerview.widget.RecyclerView parent) {
    if (getOrientation(parent) == LinearLayoutManager.VERTICAL) {
        view.measure(View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        view.layout(parent.getPaddingLeft(),
                0,
                parent.getWidth() - parent.getPaddingRight(),
                view.getMeasuredHeight());
    } else {
        view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(parent.getMeasuredHeight() - parent.getPaddingTop() - parent.getPaddingBottom(), View.MeasureSpec.EXACTLY));
        view.layout(0,
                parent.getPaddingTop(),
                view.getMeasuredWidth(),
                parent.getHeight() - parent.getPaddingBottom());
    }
}
 
Example 4
Source File: LicensesActivity.java    From BonjourBrowser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_license);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mAdapter = new OpenSourceComponentAdapter(this, LICENSE_SOFTWARE, new String[]{
            ANDROID_ASSETS_FILE_PATH + ANDROID_OPEN_SOURCE_PROJECT_LICENSE,
            ANDROID_ASSETS_FILE_PATH + ANDROID_OPEN_SOURCE_PROJECT_LICENSE,
            ANDROID_ASSETS_FILE_PATH + ANDROID_OPEN_SOURCE_PROJECT_LICENSE,
            ANDROID_ASSETS_FILE_PATH + ANDROID_SOFTWARE_DEVELOPMENT_KIT,
            ANDROID_ASSETS_FILE_PATH + APACHE_LICENSE,
            ANDROID_ASSETS_FILE_PATH + APACHE_LICENSE
    });

    RecyclerView recyclerView = ((RecyclerView) findViewById(R.id.recycler_view));
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setAdapter(mAdapter);
}
 
Example 5
Source File: ChannelActivity.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
private void setupPanels() {
    final PanelAdapter mPanelsAdapter = new PanelAdapter(getActivity());
    LinearLayoutManager llm = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    mPanelsRecyclerView.setAdapter(mPanelsAdapter);
    mPanelsRecyclerView.setLayoutManager(llm);

    GetPanelsTask mTask = new GetPanelsTask(info.getStreamerName(), mPanelsAdapter::addPanels);
    mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
 
Example 6
Source File: StickyHeaderPositioner.java    From StickyHeaders with Apache License 2.0 5 votes vote down vote up
private void checkElevation() {
    if (headerElevation != NO_ELEVATION && currentHeader != null) {
        if (orientation == LinearLayoutManager.VERTICAL && currentHeader.getTranslationY() == 0
                || orientation == LinearLayoutManager.HORIZONTAL && currentHeader.getTranslationX() == 0) {
            elevateHeader();
        } else {
            settleHeader();
        }
    }
}
 
Example 7
Source File: HeaderPositionCalculator.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if an item is obscured by a header
 *
 * @param parent
 * @param item        to determine if obscured by header
 * @param header      that might be obscuring the item
 * @param orientation of the {@link RecyclerView}
 * @return true if the item view is obscured by the header view
 */
private boolean itemIsObscuredByHeader(RecyclerView parent, View item, View header, int orientation) {
    RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) item.getLayoutParams();
    Rect headerMargins = mDimensionCalculator.getMargins(header);

    int adapterPosition = parent.getChildAdapterPosition(item);
    if (adapterPosition == RecyclerView.NO_POSITION || mHeaderProvider.getHeader(parent, adapterPosition) != header) {
        // Resolves https://github.com/timehop/sticky-headers-recyclerview/issues/36
        // Handles an edge case where a trailing header is smaller than the current sticky header.
        return false;
    }

    if (orientation == LinearLayoutManager.VERTICAL) {
        int itemTop = item.getTop() - layoutParams.topMargin;
        int headerBottom = header.getBottom() + headerMargins.bottom + headerMargins.top;
        if (itemTop > headerBottom) {
            return false;
        }
    } else {
        int itemLeft = item.getLeft() - layoutParams.leftMargin;
        int headerRight = header.getRight() + headerMargins.right + headerMargins.left;
        if (itemLeft > headerRight) {
            return false;
        }
    }

    return true;
}
 
Example 8
Source File: StickyHeaderPositioner.java    From StickyHeaders with Apache License 2.0 5 votes vote down vote up
private boolean headerIsOffset(View headerForPosition) {
    if (headerForPosition != null) {
        return orientation == LinearLayoutManager.VERTICAL ?
                headerForPosition.getY() > 0 : headerForPosition.getX() > 0;
    }
    return false;
}
 
Example 9
Source File: HeaderPositionCalculator.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
private void initDefaultHeaderOffset(@NonNull Rect headerMargins, @NonNull RecyclerView recyclerView, @NonNull View header, @NonNull 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;
        translationY = Math.max(
                firstView.getTop() - topMargin - header.getHeight() - 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 10
Source File: PinchZoomItemTouchListener.java    From RecyclerViewExtensions with MIT License 5 votes vote down vote up
private float getSpan(ScaleGestureDetector detector) {
    if (mOrientation == LinearLayoutManager.VERTICAL) {
        return detector.getCurrentSpanY();
    } else {
        return detector.getCurrentSpanX();
    }
}
 
Example 11
Source File: LayoutInfoUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Return the accumulated height of ComponentTreeHolders, or return the {@param maxHeight} if the
 * accumulated height is higher than the {@param maxHeight}.
 */
public static int computeLinearLayoutWrappedHeight(
    LinearLayoutManager linearLayoutManager,
    int maxHeight,
    List<ComponentTreeHolder> componentTreeHolders) {
  final int itemCount = componentTreeHolders.size();
  int measuredHeight = 0;

  switch (linearLayoutManager.getOrientation()) {
    case LinearLayoutManager.VERTICAL:
      for (int i = 0; i < itemCount; i++) {
        final ComponentTreeHolder holder = componentTreeHolders.get(i);

        measuredHeight += holder.getMeasuredHeight();
        measuredHeight += LayoutInfoUtils.getTopDecorationHeight(linearLayoutManager, i);
        measuredHeight += LayoutInfoUtils.getBottomDecorationHeight(linearLayoutManager, i);

        if (measuredHeight > maxHeight) {
          measuredHeight = maxHeight;
          break;
        }
      }
      return measuredHeight;

    case LinearLayoutManager.HORIZONTAL:
    default:
      throw new IllegalStateException(
          "This method should only be called when orientation is vertical");
  }
}
 
Example 12
Source File: StickyHeaderPositioner.java    From StickyHeaders with Apache License 2.0 5 votes vote down vote up
private float offsetHeader(View nextHeader) {
    boolean shouldOffsetHeader = shouldOffsetHeader(nextHeader);
    float offset = -1;
    if (shouldOffsetHeader) {
        if (orientation == LinearLayoutManager.VERTICAL) {
            offset = -(currentHeader.getHeight() - nextHeader.getY());
            currentHeader.setTranslationY(offset);
        } else {
            offset = -(currentHeader.getWidth() - nextHeader.getX());
            currentHeader.setTranslationX(offset);
        }
    }
    return offset;
}
 
Example 13
Source File: HomeCategoriesFragment.java    From GooglePlayCloned with Apache License 2.0 5 votes vote down vote up
private void configureRecyclerViews() {
    topCategoriesRecyclerView = view.findViewById(R.id.rv_top_categories);
    topCategoriesRecyclerView.setHasFixedSize(true);
    RecyclerView.LayoutManager horizontalLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
    topCategoriesRecyclerView.setLayoutManager(horizontalLayoutManager);

    allCategoriesRecyclerView = view.findViewById(R.id.rv_all_categories);
    allCategoriesRecyclerView.setHasFixedSize(true);
    RecyclerView.LayoutManager verticalLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    allCategoriesRecyclerView.setLayoutManager(verticalLayoutManager);

    loadDataAndSetAdapter();
}
 
Example 14
Source File: DetailsFragment.java    From ArchPackages with GNU General Public License v3.0 5 votes vote down vote up
private void populateRecyclerView(RecyclerView recyclerView, List<String> stringList) {
    if (stringList != null && !stringList.isEmpty()) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setHasFixedSize(true);
        recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        DependencyAdapter dependencyAdapter = new DependencyAdapter(this);
        recyclerView.setAdapter(dependencyAdapter);
        dependencyAdapter.submitList(stringList);
    }
}
 
Example 15
Source File: ImagePagerFragment.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms current Preferences orientation into LinearLayoutManager orientation code
 *
 * @return Preferred orientation, as LinearLayoutManager orientation code
 */
private int getOrientation() {
    if (Preferences.Constant.PREF_VIEWER_ORIENTATION_HORIZONTAL == Preferences.getViewerOrientation()) {
        return LinearLayoutManager.HORIZONTAL;
    } else {
        return LinearLayoutManager.VERTICAL;
    }
}
 
Example 16
Source File: MultipleDaysFragment.java    From weather with Apache License 2.0 5 votes vote down vote up
private void initRecyclerView() {
  LinearLayoutManager layoutManager
      = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
  recyclerView.setLayoutManager(layoutManager);
  mItemAdapter = new ItemAdapter<>();
  mFastAdapter = FastAdapter.with(mItemAdapter);
  recyclerView.setItemAnimator(new DefaultItemAnimator());
  recyclerView.setAdapter(mFastAdapter);
}
 
Example 17
Source File: FavoritesFragment.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
@Override
protected RecyclerView.LayoutManager getLayoutManager()
{
    return new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
}
 
Example 18
Source File: MainActivity.java    From AndroidDemo with MIT License 4 votes vote down vote up
private void initDbData() {// 初始化RecyclerView数据,把数据库内容写入
    mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mAdapter = new MyAdapter(getStudentList());
}
 
Example 19
Source File: ChatAttachAlertPhotoLayout.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onCustomMeasure(View view, int width, int height) {
    boolean isPortrait = width < height;
    if (view == cameraIcon) {
        cameraIcon.measure(View.MeasureSpec.makeMeasureSpec(itemSize, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(itemSize - cameraViewOffsetBottomY - cameraViewOffsetY, View.MeasureSpec.EXACTLY));
        return true;
    } else if (view == cameraView) {
        if (cameraOpened && !cameraAnimationInProgress) {
            cameraView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
            return true;
        }
    } else if (view == cameraPanel) {
        if (isPortrait) {
            cameraPanel.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(126), View.MeasureSpec.EXACTLY));
        } else {
            cameraPanel.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(126), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
        }
        return true;
    } else if (view == zoomControlView) {
        if (isPortrait) {
            zoomControlView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(50), View.MeasureSpec.EXACTLY));
        } else {
            zoomControlView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(50), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
        }
        return true;
    } else if (view == cameraPhotoRecyclerView) {
        cameraPhotoRecyclerViewIgnoreLayout = true;
        if (isPortrait) {
            cameraPhotoRecyclerView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), View.MeasureSpec.EXACTLY));
            if (cameraPhotoLayoutManager.getOrientation() != LinearLayoutManager.HORIZONTAL) {
                cameraPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
                cameraPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                cameraAttachAdapter.notifyDataSetChanged();
            }
        } else {
            cameraPhotoRecyclerView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
            if (cameraPhotoLayoutManager.getOrientation() != LinearLayoutManager.VERTICAL) {
                cameraPhotoRecyclerView.setPadding(0, AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8));
                cameraPhotoLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                cameraAttachAdapter.notifyDataSetChanged();
            }
        }
        cameraPhotoRecyclerViewIgnoreLayout = false;
        return true;
    }
    return false;
}
 
Example 20
Source File: SelectDeviceDialog.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);

    adapter = new ScannedDevicesAdapter(new DeviceInfoViewHolder.Generator(R.layout.device_item) {
        @Override
        public DeviceInfoViewHolder generate(View itemView) {
            final ViewHolder holder = new ViewHolder(itemView);
            holder.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int adapterPos = holder.getAdapterPosition();
                    if (adapterPos != RecyclerView.NO_POSITION) {
                        BluetoothDeviceInfo devInfo = (BluetoothDeviceInfo) adapter.getDevicesInfo().get(adapterPos);
                        connect(devInfo);
                    }
                }
            });
            return holder;
        }

    }, context);

    discovery = new Discovery(adapter, this);

    adapter.setThermometerMode();

    discovery.connect(context);

    layout = new GridLayoutManager(context, context.getResources().getInteger(R.integer.device_selection_columns), LinearLayoutManager.VERTICAL, false);
    itemDecoration = new RecyclerView.ItemDecoration() {
        final int horizontalMargin = getResources().getDimensionPixelSize(R.dimen.item_margin);

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            final int columns = layout.getSpanCount();
            if (columns == 1) {
                outRect.set(0, 0, 0, 0);
            } else {
                int itemPos = parent.getChildAdapterPosition(view);
                if (itemPos % columns == columns - 1) {
                    outRect.set(0, 0, 0, 0);
                } else {
                    outRect.set(0, 0, horizontalMargin, 0);
                }
            }
        }
    };
}