Попробуйте это ...
ваша активность ..
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.addItemDecoration(new OverlapDecoration());
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(new TestAdapter(25,this));
}
}
Используйте AdditemDecoration для перекрытия
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class OverlapDecoration extends RecyclerView.ItemDecoration {
private final static int vertOverlap = -40;
@Override
public void getItemOffsets (Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
final int itemPosition = parent.getChildAdapterPosition(view);
if (itemPosition == 0) {
return; }
outRect.set(0, vertOverlap, 0, 0);
}
}
Ваш адаптер
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
public class TestAdapter extends RecyclerView.Adapter<TextViewHolder> {
private static final int ITEM_VIEW_TYPE_ITEM = 0;
private static final int ITEM_VIEW_TYPE_ADD = 1;
private List<String> labels;
Context context;
public TestAdapter(int count, Context context) {
labels = new ArrayList<String>(count);
this.context=context;
for (int i = 0; i < count; ++i) {
labels.add(String.valueOf(i));
}
}
@Override
public TextViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate( R.layout.item_add, parent, false);
return new TextViewHolder(view);
}
@Override
public void onBindViewHolder(final TextViewHolder holder, final int position) {
if (position == labels.size()) {
holder.textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addItem();
}
});
return;
}
if(position%2==0)
{
holder.textView.setBackground(ContextCompat.getDrawable(context,R.drawable.green_background_back));
}
else
{
holder.textView.setBackground(ContextCompat.getDrawable(context,R.drawable.green_background_back_white));
}
final String label = labels.get(position);
holder.textView.setText(label);
holder.textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeItem(holder.getPosition());
}
});
}
private void addItem() {
if (labels.size() >=1){
int lastItem = Integer.parseInt(labels.get(labels.size() - 1));
labels.add(String.valueOf(lastItem + 1));
notifyItemInserted(labels.size() - 1);
} else {
labels.add(new String("0"));
notifyItemInserted(0);
}
}
private void removeItem(int position) {
labels.remove(position);
notifyItemRemoved(position);
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public int getItemCount() {
return labels.size() + 1;
}
}
activity_recycler_view. xml
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/item_margin"
android:clipToPadding="false"/>
расположение адаптера
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/green_900"
android:background="@drawable/green_background_back"
android:padding="30dp"
android:text="@string/add_item"/>
Возможность изменения фона макета
green_background_back. xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
<corners android:topRightRadius="25dp"
android:topLeftRadius="25dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
<solid android:color="@android:color/darker_gray" />
</shape>
green_background_back_white. xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
<corners android:topRightRadius="25dp"
android:topLeftRadius="25dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
<solid android:color="@android:color/white" />
</shape>
Результат
введите описание изображения здесь