1

I am having trouble trying to create an adapter for a TwoWayView from lucasar. https://github.com/lucasr/twoway-view

What I want is a facebook-style display for images. Sort of like this. facebook style image structure

I am currently trying to convert the LayoutAdapter.java file in the github repo under the sample folder into an Adapter that I can use in my project, but I think I need some more information on what exactly this adapter is doing.

Here is the xml for the TwoWayView grid.

<org.lucasr.twowayview.widget.TwoWayView
    android:id="@+id/twvGrid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    app:twowayview_layoutManager="SpannableGridLayoutManager"
    app:twowayview_numColumns="3"
    app:twowayview_numRows="3"
    android:layout_below="@+id/youtubeVidImage"
    android:layout_gravity="center"
    android:fitsSystemWindows="true"
    android:layout_marginTop="35dp"/>

Each Item in the layout (GalleryItem) is essentially just a url of an image to be displayed. And I want to be able to add these images to the layout in the Activity that set up the TwoWayView. Something like this for the code in the Activity that initializes the mPhotos array.

    private void initImagesRecyclerView(){
        Log.d(TAG, "initImagesRecyclerView: init Recyclerview");
        imagesRecyclerView = findViewById(R.id.twvGrid);
        mPhotos =  new ArrayList<GalleryItem>();
        //mImagePostsAdapter = new ImagePostsAdapter(this,mPhotos);
        //imagesRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL));
        mImagePostsAdapter = new TwoWayViewAdapter(this,imagesRecyclerView,R.layout.layout_staggered_grid);
        imagesRecyclerView.setAdapter(mImagePostsAdapter);
    }

Can anyone give me some advice on how to implement the TwoWayView? Anything on how to make the adapter and how to set it to the TwoWayView reference in the Activity would be great.

Thanks

  • You can do the structure you want by Using StaggeredGridLayoutManager in a horizontal RecyclerView and change the size of the first item in the grid, Without Using any external library like twoway-view – MR3YY Sep 11 '20 at 16:17
  • Oh okay, so maybe I could do something like: If there is one image, then that will take up an entire row on the grid, and if there are 3 images, then I could put two on the first row on the grid and have the third image span across the next row all by itself? And I would programmatically decide which images share a row on the grid and which images take up a whole row? I'll look more into StaggeredGridLayoutManager, thanks – Nathan Wolf Sep 11 '20 at 16:36

0 Answers0