Hinweis: Die Größe von Einladungen kann je nach Status des Elements vergrößert oder verkleinert werden und auch „Präsent“ sein.
Ich habe Folgendes erreicht, aber die Ausrichtung passt nicht für dynamische Änderungen. Zur Verdeutlichung sehen Sie sich bitte den Screenshot an:
https://i.sstatic.net/mssFl.gif
Code: Select all
SeparationDecoratorCode: Select all
public class SeparationDecorator extends RecyclerView.ItemDecoration
{
private int textSize = 50;
private int groupSpacing = 100;
private static int printPresentAt;
private static int printInviteAt;
private Paint paint = new Paint();
{
paint.setTextSize(textSize);
}
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
{
// TODO : Alignment Problem
for (int i = 0; i < parent.getChildCount(); i++)
{
View view = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(view);
int present = MyGlobal.getPresentCount();
int invited = MyGlobal.getInviteCount();
if (present == 0 && invited > 0)
{
SeparationDecorator.printPresentAt = invited;
SeparationDecorator.printInviteAt = 0;
}
else if (present > 0 && invited > 0)
{
SeparationDecorator. printPresentAt = 0;
SeparationDecorator.printInviteAt = present;
}
else if (present > 0 && invited == 0)
{
SeparationDecorator.printPresentAt = 0;
SeparationDecorator.printInviteAt = present;
}
if (position == SeparationDecorator.printPresentAt)
{
c.drawText("Present", view.getLeft(),
view.getTop() - groupSpacing + textSize, paint);
}
else
{
if (position == SeparationDecorator.printInviteAt)
{
c.drawText("Invited", view.getLeft(),
view.getTop() - groupSpacing + textSize, paint);
}
}
}
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (parent.getChildAdapterPosition(view) == SeparationDecorator.printInviteAt
||parent.getChildAdapterPosition(view) == SeparationDecorator.printPresentAt) {
outRect.set(0, groupSpacing, 0, 0);
}
}
}
Code: Select all
MyGlobal.getPresentCount()Code: Select all
MyGlobal.getInviteCount()Sie ändern sich dynamisch.
Elementklasse:
Code: Select all
public class FriendsModel
{
String userName;
String handleName;
int status;
/*
* 0 - Invited
* 1 - Accepted
*
* */
String fcm;
String uid;
public FriendsModel(String userName, String handleName, int status, String fcm, String uid)
{
this.userName = userName;
this.handleName = handleName;
this.status = status;
this.fcm = fcm;
this.uid = uid;
}
public FriendsModel()
{ }
@Override
public boolean equals(Object obj) {
FriendsModel model = (FriendsModel) obj;
if (this.uid.equals(model.uid))
return true;
return false;
}
/* All getters and setters */
}
Mobile version