Я пытаюсь создать spannable recyclerView, например, следующее изображение, используя библиотеку TwoWayView: https://github.com/lucasr/twoway-view
Но я не могу получить желаемый вид, и пустые ячейки остаются в стороне.
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);
}
XML:
<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"/>
Изменить 1 Я смог решить это, изменив rowWidth на 12 в XML и следующие интервалы:
//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;
}