2016-08-28 7 views
10

इम तरह Spannable RecyclerView निम्न छवि TwoWayView लाइब्रेरी का उपयोग कर की तरह एक spannable recyclerView बनाने का प्रयास कर: https://github.com/lucasr/twoway-viewSnapchat-डिस्कवर

लेकिन मैं वांछित दृश्य प्राप्त करने में असमर्थ हूँ और वहाँ रिक्त कक्षों से बाहर छोड़ दिया जा रहा है।

 final SpannableGridLayoutManager.LayoutParams lp = (SpannableGridLayoutManager.LayoutParams) itemView.getLayoutParams(); 

     //final int span1 = (itemId == 0 || itemId == 3 ? 2 : 1); 
     //final int span2 = (itemId == 0 ? 2 : (itemId == 3 ? 3 : 1)); 

     int span1 = 0; //h 
     int span2 = 0; //w 

     switch(itemId) 
     { 
     case 0: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 1: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 2: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 3: 
      span1 = 3; 
      span2 = 1; 
      break; 

     case 4: 
      span1 = 3; 
      span2 = 1; 
      break; 

     case 5: 
      span1 = 4; 
      span2 = 3; 
      break; 

     case 6: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 7: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 8: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 9: 
      span1 = 2; 
      span2 = 1; 
      break; 

     case 10: 
      span1 = 4; 
      span2 = 3; 
      break; 
     } 

     final int colSpan = span2; 
     final int rowSpan = span1; 

     if (lp.rowSpan != rowSpan || lp.colSpan != colSpan) 
     { 
      lp.rowSpan = rowSpan; 
      lp.colSpan = colSpan; 
      itemView.setLayoutParams(lp); 
     } 

एक्सएमएल:

<org.lucasr.twowayview.widget.TwoWayView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    style="@style/TwoWayView" 
    app:twowayview_layoutManager="ListLayoutManager"/> 

रेफरी: enter image description here

संपादित करें 1 मैं XML में से 12 rowWidth बदल कर इस का समाधान करने में सक्षम था और निम्नलिखित फैला:

 //PADDING-- left/top/right/bottom 
    switch(itemId%11) 
    { 
    case 0: 
     span1 = 4; 
     span2 = 7; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 1: 
     span1 = 4; 
     span2 = 7; 
     //holder.cont_frienddetail.setPadding(dpAsPixels2, dpAsPixels1, dpAsPixels2, dpAsPixels1); 
     break; 

    case 2: 
     span1 = 4; 
     span2 = 7; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 3: 
     span1 = 4; 
     span2 = 7; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 4: 
     span1 = 8; 
     span2 = 14; 
     //holder.cont_frienddetail.setPadding(dpAsPixels2, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 5: 
     span1 = 4; 
     span2 = 7; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 6: 
     span1 = 6; 
     span2 = 10; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels2, dpAsPixels1); 
     break; 

    case 7: 
     span1 = 6; 
     span2 = 10; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 8: 
     span1 = 8; 
     span2 = 14; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels2, dpAsPixels1); 
     break; 

    case 9: 
     span1 = 4; 
     span2 = 7; 
     ///holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 

    case 10: 
     span1 = 4; 
     span2 = 7; 
     //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
     break; 
    } 
+0

तो तुम एक शीर्ष सूची है कि कुछ समय के बाद और के साथ एक सूची के नीचे स्क्रॉल है बनाने के लिए कोशिश कर रहे हैं कार्ड के विभिन्न प्रकार के आकार? –

+0

आप पंक्ति Width – Tuna

उत्तर

1

मैं XML में से 12 rowWidth बदल कर इस का समाधान करने में सक्षम था और निम्नलिखित फैला:

 //PADDING-- left/top/right/bottom 
switch(itemId%11) 
{ 
case 0: 
    span1 = 4; 
    span2 = 7; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 1: 
    span1 = 4; 
    span2 = 7; 
    //holder.cont_frienddetail.setPadding(dpAsPixels2, dpAsPixels1, dpAsPixels2, dpAsPixels1); 
    break; 

case 2: 
    span1 = 4; 
    span2 = 7; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 3: 
    span1 = 4; 
    span2 = 7; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 4: 
    span1 = 8; 
    span2 = 14; 
    //holder.cont_frienddetail.setPadding(dpAsPixels2, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 5: 
    span1 = 4; 
    span2 = 7; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 6: 
    span1 = 6; 
    span2 = 10; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels2, dpAsPixels1); 
    break; 

case 7: 
    span1 = 6; 
    span2 = 10; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 8: 
    span1 = 8; 
    span2 = 14; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels2, dpAsPixels1); 
    break; 

case 9: 
    span1 = 4; 
    span2 = 7; 
    ///holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 

case 10: 
    span1 = 4; 
    span2 = 7; 
    //holder.cont_frienddetail.setPadding(dpAsPixels0, dpAsPixels1, dpAsPixels0, dpAsPixels1); 
    break; 
} 
-1

इस लिंक The link you getting help

Full source code

enter image description here

कोड देखें।

MainActivity.java

import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.Menu; 
import android.view.MenuItem; 


public class MainActivity extends AppCompatActivity { 

    public static final String TYPE_VERTICAL_LIST= "Vertical List"; 
    public static final String TYPE_HORIZONTAL_LIST= "Horizontal List"; 
    public static final String TYPE_GRID_VIEW = "Grid View"; 
    public static final String TYPE_HORIZONTAL_GRID_VIEW_STAGGERED = "HorizontalStaggeredGridView"; 
    public static final String TYPE_VERTICAL_GRID_VIEW_STAGGERED = "VerticalStaggeredGridView"; 
    public static final String TYPE = "TYPE"; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    attachFragment(TYPE_VERTICAL_LIST); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    /** Return false so that we can capture {@link PlaceholderFragment#onOptionsItemSelected(android.view.MenuItem)} events in {@link PlaceholderFragment} Fragment*/ 
    return false; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 

    switch (item.getItemId()){ 
     case R.id.action_vertical_list: 
     attachFragment(TYPE_VERTICAL_LIST); 
     break; 
     case R.id.action_horizontal_list: 
     attachFragment(TYPE_HORIZONTAL_LIST); 
     break; 
     case R.id.action_grid_view: 
     attachFragment(TYPE_GRID_VIEW); 
     break; 
     case R.id.action_vertical_grid_view_staggered: 
     attachFragment(TYPE_VERTICAL_GRID_VIEW_STAGGERED); 
     break; 
     case R.id.action_horizontal_grid_view_staggered: 
     attachFragment(TYPE_HORIZONTAL_GRID_VIEW_STAGGERED); 
     break; 
    } 

    return super.onOptionsItemSelected(item); 
    } 


    /** Attach placeholder fragment here and show different kind of RecyclerView flavours eg List or grid based on user selection in the options menu.*/ 
    private void attachFragment(String type){ 
    Bundle bundle = new Bundle(); 
    bundle.putString(TYPE, type); 
    PlaceholderFragment placeholderFragment = new PlaceholderFragment(); 
    placeholderFragment.setArguments(bundle); 
    getSupportFragmentManager().beginTransaction().replace(R.id.container, placeholderFragment).commit(); 
    } 
    } 

PlaceholderFragment.java

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v7.widget.DefaultItemAnimator; 
import android.support.v7.widget.GridLayoutManager; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.support.v7.widget.StaggeredGridLayoutManager; 
import android.view.LayoutInflater; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 

import java.util.ArrayList; 


public class PlaceholderFragment extends Fragment { 

    private static final String TAG = "PlaceholderFragment"; 
    /*Number of columns in the grid view*/ 
    private static final int NUM_OF_COLUMNS = 2; 
    /*Total number of items in the RecyclerView*/ 
    private static final int NUM_OF_ITEMS = 100; 
    private ArrayList<DataModel> mDataModels; 
    private RecyclerView recyclerView; 
    private RecyclerViewAdapter recyclerViewAdapter; 
    private int addItemCount = 0; 


    public PlaceholderFragment() { 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
     //Must be set in order to capture menu item click events. If you don't set it, it will not show the menu items set in the Activity holding this fragment. 
     setHasOptionsMenu(true); 
     View rootView = inflater.inflate(R.layout.fragment_main, container, false); 
     recyclerView = (RecyclerView)rootView.findViewById(R.id.recyclerview); 


     RecyclerView.LayoutManager layoutManager = null; 
     String type = getArguments().getString(MainActivity.TYPE); 
     if(type.equals(MainActivity.TYPE_VERTICAL_LIST)){ 
      /*LinearLayoutManager to show a vertical list view*/ 
      layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); 
     }else if(type.equals(MainActivity.TYPE_HORIZONTAL_LIST)){ 
      /*LinearLayoutManager to show a horizontal list view*/ 
      layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); 
     }else if(type.equals(MainActivity.TYPE_GRID_VIEW)){ 
      /*LinearLayoutManager to show a grid view. We can specify number of columns in the grid.*/ 
      layoutManager = new GridLayoutManager(getActivity(), NUM_OF_COLUMNS); 

     }else if(type.equals(MainActivity.TYPE_HORIZONTAL_GRID_VIEW_STAGGERED)){ 
      /*LinearLayoutManager to show a staggered grid view. We can specify number of columns in the grid.*/ 
      //spanCount: If orientation is vertical, spanCount is number of columns. If orientation is horizontal, spanCount is number of rows. 
      //orientation: StaggeredGridLayoutManager.HORIZONTAL or StaggeredGridLayoutManager.HORIZONTAL 
      layoutManager = new StaggeredGridLayoutManager(3/*span count*/, StaggeredGridLayoutManager.HORIZONTAL/* orientation*/); 

     }else if(type.equals(MainActivity.TYPE_VERTICAL_GRID_VIEW_STAGGERED)){ 
      /*LinearLayoutManager to show a staggered grid view. We can specify number of columns in the grid.*/ 
      //spanCount: If orientation is vertical, spanCount is number of columns. If orientation is horizontal, spanCount is number of rows. 
      //orientation: StaggeredGridLayoutManager.HORIZONTAL or StaggeredGridLayoutManager.HORIZONTAL 
      layoutManager = new StaggeredGridLayoutManager(2/*span count*/, StaggeredGridLayoutManager.VERTICAL/* orientation*/); 

     } 

     recyclerView.setLayoutManager(layoutManager); 
     mDataModels = getDataModelList(); 
     recyclerViewAdapter = new RecyclerViewAdapter(mDataModels, type); 

     /*Third party ItemDecoration found from https://gist.github.com/alexfu/0f464fc3742f134ccd1e*/ 
     RecyclerView.ItemDecoration verticalDivider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST); 
     RecyclerView.ItemDecoration horizontalDivider = new DividerItemDecoration(getActivity(), DividerItemDecoration.HORIZONTAL_LIST); 
     recyclerView.addItemDecoration(horizontalDivider); 
     recyclerView.addItemDecoration(verticalDivider); 

     // this is the default; 
     // this call is actually only necessary with custom ItemAnimators 
     recyclerView.setItemAnimator(new DefaultItemAnimator()); 

     recyclerView.setAdapter(recyclerViewAdapter); 
     return rootView; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 

     switch (item.getItemId()){ 
      case R.id.action_add_item: 
       addItem(); 
       break; 
      case R.id.action_delete_item: 
       deleteItem(); 
       break; 

     } 

     return super.onOptionsItemSelected(item); 
    } 

    /** Creates and returns the data items to be shown in the Recycler View*/ 
    private ArrayList<DataModel> getDataModelList(){ 
     ArrayList<DataModel> dataModels = new ArrayList<>(); 

     for (int i = 0; i < NUM_OF_ITEMS; i++) { 
      dataModels.add(new DataModel("Title:"+i)); 
     } 

     return dataModels; 
    } 


    /** Adds a single item in the existing list*/ 
    private final void addItem(){ 
     //Adding item at top second position(i.e. at index 1). 
     mDataModels.set(1, new DataModel("Added Item "+String.valueOf(++addItemCount))); 
     //See for similar methods to know more item insertion options 
     recyclerViewAdapter.notifyItemInserted(1); 
    } 

    /** Deletes a single item from the existing list*/ 
    private void deleteItem(){ 
     //Removing top item 
     mDataModels.remove(0); 
     //See for similar methods to know more item removing options 
     recyclerViewAdapter.notifyItemRemoved(0); 
    } 

} 

ListItemViewHolder.java

public class ListItemViewHolder extends ViewHolder { 

ImageView imgView; 
TextView title; 

public ListItemViewHolder(View itemView) { 
    super(itemView); 
    title = (TextView) itemView.findViewById(R.id.textview_title); 
    imgView = (ImageView) itemView.findViewById(R.id.imageview_icon); 
} 
} 

DividerItemDecoration.java

import android.content.Context; 
import android.content.res.TypedArray; 
import android.graphics.Canvas; 
import android.graphics.Rect; 
import android.graphics.drawable.Drawable; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.view.View; 


public class DividerItemDecoration extends RecyclerView.ItemDecoration { 

    private static final int[] ATTRS = new int[]{ 
      android.R.attr.listDivider 
    }; 

    public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 

    public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 

    private Drawable mDivider; 

    private int mOrientation; 

    public DividerItemDecoration(Context context, int orientation) { 
     final TypedArray a = context.obtainStyledAttributes(ATTRS); 
     mDivider = a.getDrawable(0); 
     a.recycle(); 
     setOrientation(orientation); 
    } 

    public void setOrientation(int orientation) { 
     if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 
      throw new IllegalArgumentException("invalid orientation"); 
     } 
     mOrientation = orientation; 
    } 

    @Override 
    public void onDraw(Canvas c, RecyclerView parent) { 
     if (mOrientation == VERTICAL_LIST) { 
      drawVertical(c, parent); 
     } else { 
      drawHorizontal(c, parent); 
     } 
    } 

    public void drawVertical(Canvas c, RecyclerView parent) { 
     final int left = parent.getPaddingLeft(); 
     final int right = parent.getWidth() - parent.getPaddingRight(); 

     final int childCount = parent.getChildCount(); 
     for (int i = 0; i < childCount; i++) { 
      final View child = parent.getChildAt(i); 
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 
        .getLayoutParams(); 
      final int top = child.getBottom() + params.bottomMargin; 
      final int bottom = top + mDivider.getIntrinsicHeight(); 
      mDivider.setBounds(left, top, right, bottom); 
      mDivider.draw(c); 
     } 
    } 

    public void drawHorizontal(Canvas c, RecyclerView parent) { 
     final int top = parent.getPaddingTop(); 
     final int bottom = parent.getHeight() - parent.getPaddingBottom(); 

     final int childCount = parent.getChildCount(); 
     for (int i = 0; i < childCount; i++) { 
      final View child = parent.getChildAt(i); 
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 
        .getLayoutParams(); 
      final int left = child.getRight() + params.rightMargin; 
      final int right = left + mDivider.getIntrinsicHeight(); 
      mDivider.setBounds(left, top, right, bottom); 
      mDivider.draw(c); 
     } 
    } 

    @Override 
    public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { 
     if (mOrientation == VERTICAL_LIST) { 
      outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 
     } else { 
      outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 
     } 
    } 
} 

RecyclerViewAdapter.java

import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

import java.util.ArrayList; 

public class RecyclerViewAdapter extends RecyclerView.Adapter<ListItemViewHolder> { 


    private ArrayList<DataModel> mDataModels; 
    private String mType; 

    public RecyclerViewAdapter(ArrayList<DataModel> mDataModels, String mType) { 
     this.mDataModels = mDataModels; 
     this.mType = mType; 
    } 


    @Override 
    public ListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_view, parent, false); 
     return new ListItemViewHolder(itemView); 
    } 


    @Override 
    public void onBindViewHolder(ListItemViewHolder holder, int position) { 
     DataModel model = mDataModels.get(position); 
     holder.title.setText(model.getTitle()); 
     if(position % 2 == 0){ 
      if(mType.equals(MainActivity.TYPE_VERTICAL_GRID_VIEW_STAGGERED)){ 
       holder.imgView.setImageResource(R.drawable.lollipop); 
      }else{ 
       holder.imgView.setImageResource(R.drawable.lollipop_h1); 
      } 

     }else if(position % 3 == 0){ 
      if(mType.equals(MainActivity.TYPE_VERTICAL_GRID_VIEW_STAGGERED)){ 
       holder.imgView.setImageResource(R.drawable.lollipop1); 
      }else{ 
       holder.imgView.setImageResource(R.drawable.lollipop_h2); 
      } 
     }else{ 
      if(mType.equals(MainActivity.TYPE_VERTICAL_GRID_VIEW_STAGGERED)){ 
       holder.imgView.setImageResource(R.drawable.lollipop2); 
      }else{ 

       holder.imgView.setImageResource(R.drawable.lollipop_h3); 
      } 
     } 
    } 


    @Override 
    public int getItemCount() { 
     return mDataModels.size(); 
    } 
} 

DataModel.java

public class DataModel { 

    private String title; 

    public DataModel(String title) { 
     this.title = title; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 
} 

activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    tools:ignore="MergeRootFrame" /> 

fragment_main।एक्सएमएल

<android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainActivity" 
     tools:listitem="@layout/item_recycler_view" 
     /> 

</RelativeLayout> 

item_recycler_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_vertical" 
    android:padding="8dp" 
    android:background="@android:color/holo_green_dark"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageview_icon" 
     android:src="@drawable/lollipop" 
     android:scaleType="centerCrop"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/textview_title" 
     android:background="@android:color/darker_gray"/> 
</LinearLayout> 
+0

कहां बदलते हैं, लेकिन ऐसा लगता है कि यह StaggeredGridLayout की तरह अधिक है। मैं उपस्थिति को संलग्न छवि की तरह होना चाहता हूँ। मैंने वास्तव में पुस्तकालय के साथ इसे प्रबंधित किया है, लेकिन जब मैं ग्लाइड/पिकासो का उपयोग करता हूं तो कुछ त्रुटि होती है; उस पर कोई सुझाव? – Zen

+0

क्यों आप अपने यूआरएल चित्र या गंतव्य पथ के साथ पिकासो यूनिवर्सल लाइब्रेरी या गिल्ड के साथ एडाप्टर में जोड़ नहीं सकते हैं ... –

2

पूरे स्क्रीन के माध्यम से अपना उदाहरण छवि प्रत्येक कक्ष के ऊर्ध्वाधर सीमा ले रहे हैं और विस्तार की कल्पना करें। यदि आपने ऐसा किया है, तो आप देखेंगे कि छह कॉलम हैं। और वह अंतर्दृष्टि है जो आपकी समस्या का समाधान करेगी।

अब आप नियमित RecyclerView और GridLayoutManager के साथ ऐसा कर सकते हैं, और किसी को अपने गिटहब पुस्तकालय में सभी बग को ठीक करने पर निर्भर नहीं होना चाहिए।

612 कॉलम के साथ GridLayoutManager बनाएं, फिर एक कस्टम SpanSizeLookup निर्दिष्ट करें जो आपकी कोशिकाओं को अलग-अलग चौड़ाई बनाएगा।

आपकी उदाहरण छवि में, पहली पंक्ति में तीन कक्ष प्रत्येक कॉलम 2 कॉल करेंगे। दूसरी पंक्ति में दो बड़ी कोशिकाएं प्रत्येक 3 कॉलम फैलती हैं। निचला बायां सेल 4 कॉलम फैलता है।

तो अब आपको केवल SpanSizeLookup बनाना है जो सही चौड़ाई निर्धारित करेगा।

// Create a grid layout with 6 columns 
    // (least common multiple of 2 and 3) 
    GridLayoutManager layoutManager = new GridLayoutManager(this, 6); 

    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 
     @Override 
     public int getSpanSize(int position) { 

      int widthClass = determineWidth(position) // TODO here you figure out what the cell width should be 

      switch (widthClass) { 
      case SMALL: 
       return 2; // fits 3 per row 

      case MEDIUM: 
       return 3; // fits 2 per row 

      case LARGE:  // fits 2 per row, one LARGE and one SMALL 
       return 4; 

      default: 
       throw new IllegalStateException("don\'t know about widthClass " + widthClass); 
      } 
     } 
    }); 

आप मेरे मूल उत्तर को उसी प्रश्न here पर देख सकते हैं।

+0

मैं ऊंचाई कैसे बदलूं? – Zen

+0

इसके अलावा, मैं मौजूदा पुस्तकालय का उपयोग करके इसे हल करने में सक्षम था। लेकिन यदि संभव हो तो भी इसका उपयोग नहीं करना पसंद करेंगे। – Zen

+0

मेरे उत्तर में span2 ऊंचाई को संदर्भित करता है – Zen