Java Code Examples for android.support.v7.widget.LinearLayoutManager#HORIZONTAL

The following examples show how to use android.support.v7.widget.LinearLayoutManager#HORIZONTAL . 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: BangumiDetailsActivity.java    From HeroVideo-master with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化分季版本recyclerView
 */
private void initSeasonsRecycler()
{

    List<BangumiDetailsInfo.ResultBean.SeasonsBean> seasons = result.getSeasons();

    mBangumiSeasonsRecycler.setHasFixedSize(false);
    mBangumiSeasonsRecycler.setNestedScrollingEnabled(false);
    LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mBangumiSeasonsRecycler.setLayoutManager(mLinearLayoutManager);
    BangumiDetailsSeasonsAdapter mBangumiDetailsSeasonsAdapter = new BangumiDetailsSeasonsAdapter(mBangumiSeasonsRecycler, seasons);
    mBangumiSeasonsRecycler.setAdapter(mBangumiDetailsSeasonsAdapter);

    for (int i = 0, size = seasons.size(); i < size; i++)
    {
        if (seasons.get(i).getSeason_id().equals(result.getSeason_id()))
            mBangumiDetailsSeasonsAdapter.notifyItemForeground(i);
    }
}
 
Example 2
Source File: Example10EntryActivity.java    From MTransition with Apache License 2.0 6 votes vote down vote up
private void init() {
    mImgIds.add(R.mipmap.img0);
    mImgIds.add(R.mipmap.img1);
    mImgIds.add(R.mipmap.img2);
    mImgIds.add(R.mipmap.img3);
    mImgIds.add(R.mipmap.img4);

    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mRecyclerView.setLayoutManager(linearLayoutManager);
    mRecyclerView.setAdapter(new CardAdapter(this, mImgIds));
    // mRecyclerView绑定scale效果
    mCardScaleHelper = new CardScaleHelper();
    mCardScaleHelper.setCurrentItemPos(2);
    mCardScaleHelper.attachToRecyclerView(mRecyclerView);

    initBlurBackground();
}
 
Example 3
Source File: DividerItemDecoration.java    From DoingDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (dividerDrawable == null) {
        return;
    }

    //如果是第一个item,不需要divider,所以直接return
    if (parent.getChildLayoutPosition(view) < 1) {
        return;
    }

    //相当于给itemView设置margin,给divider预留空间
    if (orientation == LinearLayoutManager.VERTICAL) {
        outRect.top = dividerDrawable.getIntrinsicHeight();
    } else if (orientation == LinearLayoutManager.HORIZONTAL) {
        outRect.left = dividerDrawable.getIntrinsicWidth();
    }
}
 
Example 4
Source File: GifSelectorPanel.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
public GifSelectorPanel(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    mContext = context;

    View view = LayoutInflater.from(context).inflate(R.layout.panel_image_selector, this);
    mGifListView = (RecyclerView) view.findViewById(R.id.recycler_paint_image);
    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
    mGifListView.setLayoutManager(layoutManager);
    mGifListView.setAdapter(new GifListAdapter());
}
 
Example 5
Source File: RecycleViewDivider.java    From Bailan with Apache License 2.0 5 votes vote down vote up
/**
 * 默认分割线:高度为2px,颜色为灰色
 *
 * @param context
 * @param orientation 列表方向
 */
public RecycleViewDivider(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 6
Source File: ViewHolderBannersLayout.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
public ViewHolderBannersLayout(View view, IFragmentsManager fragmentsManager, IContentLoadListener contentLoadListener) {
    super(view);
    this.rvBanners = (RecyclerViewPager) view.findViewById(R.id.rvBanners);
    this.layoutManager = new LinearLayoutManager(view.getContext(), LinearLayoutManager.HORIZONTAL, false);
    this.rvBanners.setLayoutManager(layoutManager);
    this.rvBanners.setHasFixedSize(true);
    this.fragmentsManager = fragmentsManager;
    this.needDestroy = false;
    this.contentLoadListener = contentLoadListener;
    loadBanners(view.getContext());
}
 
Example 7
Source File: RecycleViewDivider.java    From VideoPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 默认分割线:高度为2px,颜色为灰色
 *
 * @param context
 * @param orientation 列表方向
 */
public RecycleViewDivider(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 8
Source File: CleverRecyclerViewHelper.java    From CleverRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前View的位置
 *
 * @param child 目标View
 * @return LinearLayoutManager.HORIZONTAL: View.getLeft()
 * <p>LinearLayoutManager.VERTICAL: View.getTop()
 */
public int getChildCurrentPosition(View child) {
    switch (mOrientation) {
        case LinearLayoutManager.HORIZONTAL:
            return child.getLeft();
        case LinearLayoutManager.VERTICAL:
            return child.getTop();
        default:
            return LinearLayoutManager.INVALID_OFFSET;
    }
}
 
Example 9
Source File: DividerListItemDecoration.java    From MultiType-FilePicker with Apache License 2.0 5 votes vote down vote up
public DividerListItemDecoration(Context context, int orientation, int drawableId) {
    if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) {
        throw new IllegalArgumentException("Orientation Only Support LinearLayoutManager.VERTICAL " +
                "or LinearLayoutManager.HORIZONTAL");
    }
    mOrientation = orientation;

    if (drawableId == -1) {
        final TypedArray a = context.obtainStyledAttributes(ATTRS);
        mDivider = a.getDrawable(0);
        a.recycle();
    } else {
        mDivider = ContextCompat.getDrawable(context, drawableId);
    }
}
 
Example 10
Source File: MainActivity.java    From Mockery with Apache License 2.0 5 votes vote down vote up
private void setUpRecyclerUsers(List<User> users) {
  RecyclerView rv_users = (RecyclerView) findViewById(R.id.rv_users);
  LinearLayoutManager layoutManager
      = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
  rv_users.setLayoutManager(layoutManager);

  OkRecyclerViewAdapter<User, UserViewGroup> adapter = new OkRecyclerViewAdapter<User, UserViewGroup>() {
    @Override protected UserViewGroup onCreateItemView(ViewGroup parent, int viewType) {
      return new UserViewGroup(parent.getContext());
    }
  };

  adapter.setAll(users);
  rv_users.setAdapter(adapter);
}
 
Example 11
Source File: LinearScrollView.java    From Tangram-Android with MIT License 5 votes vote down vote up
private void init() {
    setGravity(Gravity.CENTER_HORIZONTAL);
    setOrientation(VERTICAL);
    inflate(getContext(), R.layout.tangram_linearscrollview, this);
    setClickable(true);
    recyclerView = (RecyclerView) findViewById(R.id.tangram_linearscrollview_container);

    layoutManager = new GridLayoutManager(getContext(), 1, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);

    indicator = findViewById(R.id.tangram_linearscrollview_indicator);
    indicatorContainer = findViewById(R.id.tangram_linearscrollview_indicator_container);

    totalDistanceOfIndicator = Style.dp2px(34);
}
 
Example 12
Source File: MovieDetailFragment.java    From Popular-Movies-App with Apache License 2.0 5 votes vote down vote up
private void initVideosList() {
    videosAdapter = new MovieVideosAdapter(getContext());
    videosAdapter.setOnItemClickListener((itemView, position) -> onMovieVideoClicked(position));
    movieVideos.setAdapter(videosAdapter);
    movieVideos.setItemAnimator(new DefaultItemAnimator());
    movieVideos.addItemDecoration(new ItemOffsetDecoration(getActivity(), R.dimen.movie_item_offset));
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(),
            LinearLayoutManager.HORIZONTAL, false);
    movieVideos.setLayoutManager(layoutManager);
}
 
Example 13
Source File: WrapContentMaxWidthManager.java    From AndroidPlayground with MIT License 5 votes vote down vote up
public WrapContentMaxWidthManager(Context context, boolean reverseLayout, int itemWidthDp,
        int itemMarginRightDp, int itemTotalHeightDp, int marginRightDp) {
    super(context, LinearLayoutManager.HORIZONTAL, reverseLayout);
    mContext = context;
    mItemWidthPx = dp2px(itemWidthDp);
    mItemTotalHeightPx = dp2px(itemTotalHeightDp);
    mItemMarginRightPx = dp2px(itemMarginRightDp);
    mMarginRightPx = dp2px(marginRightDp);
}
 
Example 14
Source File: CleverRecyclerViewHelper.java    From CleverRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * 根据速度计算出该滑动动作需要偏移多少个view
 *
 * @param velocityX 横向速度
 * @param velocityY 纵向速度
 * @return 需要偏移的个数
 */
public int getFlingCountWithVelocity(int velocityX, int velocityY) {
    switch (mOrientation) {
        case LinearLayoutManager.HORIZONTAL:
            int childWidth = (mRecyclerView.getWidth() - mRecyclerView.getPaddingLeft() - mRecyclerView.getPaddingRight()) / mVisibleChildCount;
            return velocityX / childWidth;
        case LinearLayoutManager.VERTICAL:
            int childHeight = (mRecyclerView.getHeight() - mRecyclerView.getPaddingTop() - mRecyclerView.getPaddingBottom()) / mVisibleChildCount;
            return velocityY / childHeight;
        default:
            return 0;
    }
}
 
Example 15
Source File: RecycleViewDivider.java    From LLApp with Apache License 2.0 5 votes vote down vote up
/**
 * 默认分割线:高度为2px,颜色为灰色
 *
 * @param context
 * @param orientation 列表方向
 */
public RecycleViewDivider(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 16
Source File: DividerItemDecoration.java    From Xrv with Apache License 2.0 5 votes vote down vote up
/**
 * Draws horizontal or vertical dividers onto the parent RecyclerView.
 *
 * @param canvas The {@link Canvas} onto which dividers will be drawn
 * @param parent The RecyclerView onto which dividers are being added
 * @param state  The current RecyclerView.State of the RecyclerView
 */
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (mOrientation == LinearLayoutManager.HORIZONTAL) {
        drawHorizontalDividers(canvas, parent);
    } else if (mOrientation == LinearLayoutManager.VERTICAL) {
        drawVerticalDividers(canvas, parent);
    }
}
 
Example 17
Source File: MenuAdapter.java    From PopMenuLayout with MIT License 4 votes vote down vote up
@Override
public void onBindViewHolder(MenuViewHolder holder, int position) {
    final MenuBean menu = mMenus.get(position);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
            holder.rlRootView.getLayoutParams();
    if (mMenuWidth != -1) {
        params.width = mMenuWidth;
    }
    if (mMenuHeight != -1) {
        params.height = mMenuHeight;
    }
    holder.rlRootView.setLayoutParams(params);

    holder.tvMenuText.setTextColor(mMenuTextColor);
    holder.tvMenuText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
    holder.tvMenuText.setText(menu.getText());
    holder.tvMenuText.setPadding((int) mTextPaddingLeft, (int) mTextPaddingTop,
            (int) mTextPaddingRight, (int) mTextPaddingBottom);

    if (menu.isExpandable()){
        holder.ivMenuIcon.setImageResource(mExpandableIcon);
        holder.ivMenuIcon.setVisibility(View.VISIBLE);
    }else {
        holder.ivMenuIcon.setVisibility(View.GONE);
    }

    if (mLayoutManagerOrientation == LinearLayoutManager.HORIZONTAL){
        holder.rlRootView.setBackgroundResource(mHorizontalMenuBackgroundRes);
        holder.viewDividerBottom.setVisibility(View.GONE);

        RelativeLayout.LayoutParams dividerRightParams = (RelativeLayout.LayoutParams)
                holder.viewDividerRight.getLayoutParams();
        dividerRightParams.width = (int) mDividerDp;
        dividerRightParams.setMargins(dividerRightParams.leftMargin, (int) mDividerMarginTop,
                dividerRightParams.rightMargin, (int) mDividerMarginBottom);
        holder.viewDividerRight.setLayoutParams(dividerRightParams);
        holder.viewDividerRight.setBackgroundColor(mDividerColor);
        holder.viewDividerRight.setVisibility(position == mMenus.size() - 1 ?
                View.GONE : View.VISIBLE);
    }else {
        holder.rlRootView.setBackgroundResource(mVerticalMenuBackgroundRes);
        holder.viewDividerRight.setVisibility(View.GONE);

        RelativeLayout.LayoutParams bottomRightParams = (RelativeLayout.LayoutParams)
                holder.viewDividerBottom.getLayoutParams();
        bottomRightParams.height = (int) mDividerDp;
        bottomRightParams.setMargins((int) mDividerMarginLeft, bottomRightParams.topMargin,
                (int) mDividerMarginRight, bottomRightParams.bottomMargin);
        holder.viewDividerBottom.setLayoutParams(bottomRightParams);
        holder.viewDividerBottom.setBackgroundColor(mDividerColor);
        holder.viewDividerBottom.setVisibility(position == mMenus.size() - 1 ?
                View.GONE : View.VISIBLE);
    }

    holder.tvMenuText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (onMenuClickListener != null){
                char[] indexes = menu.getIndex().toCharArray();
                int level1Index = indexes.length >= 1 ?
                        Character.getNumericValue(indexes[0]) : -1;
                int level2Index = indexes.length >= 2 ?
                        Character.getNumericValue(indexes[1]) : -1;
                int level3Index = indexes.length >= 3 ?
                        Character.getNumericValue(indexes[2]) : -1;
                onMenuClickListener.onMenuClick(level1Index, level2Index, level3Index);
            }
        }
    });
}
 
Example 18
Source File: ProductRecommentationActivity.java    From FaceT with Mozilla Public License 2.0 4 votes vote down vote up
private void sortProduct() {

        Resources res = getResources();
        final String[] categoryArray = res.getStringArray(R.array.category_type_array);
        List<ProductTypeTwo> values = new ArrayList<>(mProducts.values());
        List<String> keys = new ArrayList<>(mProducts.keySet());

        for (int i = 0; i < keys.size(); i++) {
            Log.d("otherMatchColorList.containsKey " , otherMatchColorList.size() +  " , " + i);
            if (otherMatchColorList.containsKey(keys.get(i)) && values.get(i) != null && values.get(i).getCategory().equals(categoryArray[2])) {
                Log.d(TAG + "2 sortProduct: ", keys.get(i) + " " + values.get(0).getProductName());
                mBlushProducts.put(keys.get(i), values.get(i));
            } else if (values.get(i) != null && values.get(i).getCategory().equals(categoryArray[3])) {
                Log.d(TAG + "3 sortProduct: ", keys.get(i) + " " + values.get(0).getProductName());
                mEyshadowProducts.put(keys.get(i), values.get(i));
            } else if (otherMatchColorList.containsKey(keys.get(i)) && values.get(i) != null && values.get(i).getCategory().equals(categoryArray[4])) {
                Log.d(TAG + "4 sortProduct: ", keys.get(i) + " " + values.get(0).getProductName());
                mLipstickProducts.put(keys.get(i), values.get(i));
            }
        }
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        LinearLayoutManager layoutManager2 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        LinearLayoutManager layoutManager3 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        LinearLayoutManager layoutManager4 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

        recommend_product_list_1.setLayoutManager(layoutManager1);
        mProductAdapter1 = new ProductAdapter(mFoundationProducts, getApplicationContext());
        recommend_product_list_1.setAdapter(mProductAdapter1);
        mProductAdapter1.notifyDataSetChanged();

        recommend_product_list_2.setLayoutManager(layoutManager2);
        mProductAdapter2 = new ProductAdapter(mBlushProducts, getApplicationContext());
        recommend_product_list_2.setAdapter(mProductAdapter2);
        mProductAdapter2.notifyDataSetChanged();

        recommend_product_list_3.setLayoutManager(layoutManager3);
        mProductAdapter3 = new ProductAdapter(mEyshadowProducts, getApplicationContext());
        recommend_product_list_3.setAdapter(mProductAdapter3);
        mProductAdapter3.notifyDataSetChanged();

        recommend_product_list_4.setLayoutManager(layoutManager4);
        mProductAdapter4 = new ProductAdapter(mLipstickProducts, getApplicationContext());
        recommend_product_list_4.setAdapter(mProductAdapter4);
        mProductAdapter4.notifyDataSetChanged();
    }
 
Example 19
Source File: MovieDetailFragment.java    From popular-movies-app with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.movie_detail, container, false);
    ButterKnife.bind(this, rootView);

    mMovieTitleView.setText(mMovie.getTitle());
    mMovieOverviewView.setText(mMovie.getOverview());
    mMovieReleaseDateView.setText(mMovie.getReleaseDate(getContext()));

    Picasso.with(getContext())
            .load(mMovie.getPosterUrl(getContext()))
            .config(Bitmap.Config.RGB_565)
            .into(mMoviePosterView);

    updateRatingBar();
    updateFavoriteButtons();

    // For horizontal list of trailers
    LinearLayoutManager layoutManager
            = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    mRecyclerViewForTrailers.setLayoutManager(layoutManager);
    mTrailerListAdapter = new TrailerListAdapter(new ArrayList<Trailer>(), this);
    mRecyclerViewForTrailers.setAdapter(mTrailerListAdapter);
    mRecyclerViewForTrailers.setNestedScrollingEnabled(false);

    // For vertical list of reviews
    mReviewListAdapter = new ReviewListAdapter(new ArrayList<Review>(), this);
    mRecyclerViewForReviews.setAdapter(mReviewListAdapter);

    // Fetch trailers only if savedInstanceState == null
    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_TRAILERS)) {
        List<Trailer> trailers = savedInstanceState.getParcelableArrayList(EXTRA_TRAILERS);
        mTrailerListAdapter.add(trailers);
        mButtonWatchTrailer.setEnabled(true);
    } else {
        fetchTrailers();
    }

    // Fetch reviews only if savedInstanceState == null
    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_REVIEWS)) {
        List<Review> reviews = savedInstanceState.getParcelableArrayList(EXTRA_REVIEWS);
        mReviewListAdapter.add(reviews);
    } else {
        fetchReviews();
    }

    return rootView;
}
 
Example 20
Source File: MaterialSolidWallpaper.java    From LaunchEnr with GNU General Public License v3.0 3 votes vote down vote up
private void initRecyclerView() {

        RecyclerView recyclerView = findViewById(R.id.material_rv);

        LinearLayoutManager layoutManager
                = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(layoutManager);

        //set the recycler view adapter and pass arguments to the adapter to it
        recyclerView.setAdapter(new RecyclerViewAdapter(this, SolidWallpaperUtils.material_colors));
    }