build.gradle добавить эту зависимость
implementation 'com.android.support:recyclerview-v7:27.1.1'
Класс Java
recyclerView = findViewById(R.id.recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(getBaseContext());
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(layoutManager);
seekBarList = new ArrayList();
for (int i = 0; i < 10; i++) {
seekBarList.add(i);
}
SeekBarAdapter seekBarAdapter = new SeekBarAdapter(MainActivity.this, seekBarList);
recyclerView.setAdapter(seekBarAdapter);
Класс адаптера
public class SeekBarAdapter extends RecyclerView.Adapter<SeekBarAdapter.MyViewHolder> {
private Context context;
private ArrayList<Integer> seekList;
public SeekBarAdapter(MainActivity mainActivity, ArrayList<Integer> barCodeGetList) {
this.context = mainActivity;
this.seekList = barCodeGetList;
}
@NonNull
public SeekBarAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.seekbaritem, parent, false);
return new SeekBarAdapter.MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull SeekBarAdapter.MyViewHolder holder, @SuppressLint("RecyclerView") final int position) {
if (position > 0) {
holder.img_value_indicater.setVisibility(View.GONE);
}
holder.txt_value.setText(seekList.get(position).toString());
}
@Override
public int getItemCount() {
return seekList.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView txt_value;
View view_value;
ImageView img_value_indicater;
LinearLayout lay_seekbar_margin;
MyViewHolder(View view) {
super(view);
txt_value = view.findViewById(R.id.txt_value);
view_value = view.findViewById(R.id.view_value);
img_value_indicater = view.findViewById(R.id.img_select_indicater);
lay_seekbar_margin = view.findViewById(R.id.lay_seekmargin);
}
}
}
Макет адаптера
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/lay_seekmargin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:orientation="vertical">
<View
android:id="@+id/view_value"
android:layout_width="1dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#000000" />
<TextView
android:id="@+id/txt_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" />
<ImageView
android:id="@+id/img_select_indicater"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_seek_indicator" />
</LinearLayout>
</LinearLayout>