1

I want a view similar like in the image, the half-visible card showing in right.

enter image description here

I searched so much about this and at last, I did this by using the screen width and it is working fine for all the screens sizes.

I am doing it in the fragment so in the fundScreenSize method I am getting the screen width and after getting this pass this width to the adapter.

                private void findScreenSize() {
                        DisplayMetrics displaymetrics = new DisplayMetrics();
                        if (getActivity() != null && 
                            getActivity().getWindowManager() != null) {
                            getActivity()
                            .getWindowManager()
                            .getDefaultDisplay()
                            .getMetrics(displaymetrics);
                               }
                            screenWidth = displaymetrics.widthPixels;
                           }

Here I am setting the width of current showing card according to screen width so the coming card is semi-visible in the AdapterViewHolder method.

enter code here
         public LatestStoriesAdapterViewHolder(View itemView) {
                super(itemView);
                ButterKnife.bind(this, itemView);
                if (screenWidth != 0) {
            android.view.ViewGroup.LayoutParams params = 
            itemView.getLayoutParams();
            params.width = (int) ((screenWidth * 3.4) / 4);
            itemView.setLayoutParams(params);
        }
    }

I changed this width in the view-holder and remaining code for adapter will remain same as usual.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Sandeep Insan
  • 348
  • 1
  • 7

0 Answers0