I'm new on Android studio. I made a RecyclerView with a list of data, and I implemented the event on Swiped with an ItemTouchHelper. When I swipe a child from the right to the left I see a small line like in the photo
I would hide this small line. What properties or element of the RecyclerView can be?
Down here the xml file of the activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="?android:attr/colorBackground"
tools:context=".TrippyList">
<LinearLayout
android:id="@+id/linearLayout13"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/trippyListWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/nameLabel"
android:textColor="?attr/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:text="@string/trippyWelcome2"
android:textColor="?attr/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<View
android:id="@+id/view2"
android:layout_width="300dp"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:background="#c0c0c0"
android:backgroundTint="?attr/colorPrimary"
android:visibility="visible"
app:layout_constraintWidth_percent="0.7" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout12"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/linearLayout9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.gms.ads.AdView
android:id="@+id/banner_trippylist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/trippyList_addbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:clickable="true"
android:src="@drawable/plus"
tools:srcCompat="@android:drawable/ic_menu_add" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.341"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation_bar_trippy_modify"
android:layout_width="match_parent"
android:layout_height="61dp"
android:elevation="4dp"
android:foregroundTint="?attr/colorAccent"
android:longClickable="false"
app:elevation="4dp"
app:itemIconSize="@dimen/trippy_navbar_size"
app:itemIconTint="?attr/colorAccent"
app:itemTextColor="?attr/colorAccent"
app:menu="@menu/menu" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/lista_trippy"
android:layout_width="0dp"
android:layout_height="0dp"
android:cacheColorHint="#00000000"
android:background="#00000000"
android:isScrollContainer="false"
android:keepScreenOn="false"
android:nestedScrollingEnabled="false"
android:overScrollMode="always"
android:requiresFadingEdge="none"
android:scrollIndicators="none"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbars="vertical"
android:splitMotionEvents="true"
android:verticalScrollbarPosition="defaultPosition"
app:layout_constraintBottom_toTopOf="@+id/linearLayout12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout13"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
Down the ItemTouchHelper implementation
ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.START, ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
ColorDrawable background = null;
Drawable icon = null;
if (dX > 0) {
background = new ColorDrawable(Color.RED);
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.bin);
} else {
background = new ColorDrawable(Color.BLUE);
switch (scelta) {
case "1": //delete
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.bin);
break;
case "2": // Modifica
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.modify);
break;
case "3": // Condividi
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.share);
break;
default:
icon = ContextCompat.getDrawable(getApplicationContext(), R.drawable.bin);
break;
}
}
int iconMargin = (viewHolder.itemView.getHeight() - icon.getIntrinsicHeight()) / 2;
int iconTop = viewHolder.itemView.getTop() + (viewHolder.itemView.getHeight() - icon.getIntrinsicHeight()) / 2;
int iconBottom = iconTop + icon.getIntrinsicHeight();
View itemView = viewHolder.itemView;
if (dX > 0) { // Swiping to the right
int iconLeft = itemView.getLeft() + iconMargin;
int iconRight = itemView.getLeft() + iconMargin + icon.getIntrinsicWidth();
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
background.setBounds(itemView.getLeft(), itemView.getTop(),
itemView.getLeft() + ((int) dX),
itemView.getBottom());
} else if (dX < 0) { // Swiping to the left
int iconLeft = itemView.getRight() - iconMargin - icon.getIntrinsicWidth();
int iconRight = itemView.getRight() - iconMargin;
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
background.setBounds(itemView.getRight() + ((int) dX),
itemView.getTop(), itemView.getRight(), itemView.getBottom());
} else { // view is unSwiped
background.setBounds(0, 0, 0, 0);
}
background.draw(c);
icon.draw(c);
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
AlertDialog.Builder builder = new AlertDialog.Builder(TrippyList.this);
builder.setCancelable(true);
if (direction == 4) {
switch (scelta) {
case "1": //delete
eleminaElemento(builder, viewHolder);
break;
case "2": // Modifica
curtrip = getTrippyDet(viewHolder);
Intent toTrippyMod = new Intent(getApplicationContext(), TrippyModify.class);
toTrippyMod.putExtra("currentTrip", curtrip);
toTrippyMod.putExtra("currentUser", current);
startActivity(toTrippyMod);
myAdapter.notifyItemChanged(viewHolder.getAdapterPosition());
break;
case "3": // Condividi
FragmentManager fm = getSupportFragmentManager();
ShareTrippyFragment stf = new ShareTrippyFragment(trippies.get(viewHolder.getAdapterPosition()), true);
stf.show(fm, "share_trippy_fragment");
myAdapter.notifyItemChanged(viewHolder.getAdapterPosition());
break;
default:
eleminaElemento(builder, viewHolder);
break;
}
} else {
eleminaElemento(builder, viewHolder);
}
}
});
touchHelper.attachToRecyclerView(trippyList);
Down the item layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alwaysDrawnWithCache="true"
android:animateLayoutChanges="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/trippy_row_icon"
android:layout_width="59dp"
android:layout_height="57dp"
android:layout_marginStart="36dp"
android:layout_marginTop="16dp"
app:srcCompat="@drawable/place_placeholder" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/trippy_row_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="16dp"
android:text="@string/trippyNew_city"
android:textColor="?attr/colorPrimary"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/trippy_row_dates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="12dp"
android:text="@string/trippyNew_da" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
and the recyclerview adapter
package com.trippy.trippy.ListAdapters;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.trippy.trippy.Entities.Utente;
import com.trippy.trippy.Entities.Viaggio;
import com.trippy.trippy.R;
import com.trippy.trippy.ActivityModify;
import com.trippy.trippy.TrippyList;
import com.trippy.trippy.TrippyRiepilogo;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
public class TrippyListAdapter extends RecyclerView.Adapter<TrippyListAdapter.MyViewHolder> {
private ArrayList<Viaggio> mDataset;
private Context context;
private Utente curUser;
public static class MyViewHolder extends RecyclerView.ViewHolder {
public View view;
public MyViewHolder(View v) {
super(v);
view = v;
}
}
public TrippyListAdapter(ArrayList<Viaggio> myDataset, Context context) {
mDataset = myDataset;
this.context = context;
}
@NonNull
@Override
public TrippyListAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
// create a new view
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.trippy_list_row, viewGroup, false);
Intent intent = ((Activity) context).getIntent();
curUser = intent.getExtras().getParcelable("currentUser");
MyViewHolder vh = new MyViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
TextView city = holder.view.findViewById(R.id.trippy_row_city);
TextView date = holder.view.findViewById(R.id.trippy_row_dates);
Viaggio curTrip = mDataset.get(position);
city.setText(curTrip.getLuogo());
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
date.setText(context.getText(R.string.trippy_dal) + " " + format.format(curTrip.getDaData()) + " " + context.getText(R.string.trippy_al) + " " + format.format(curTrip.getaData()));
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
long now = System.currentTimeMillis();
if(now - TrippyList.canIClick >= 1000) {
TrippyList.canIClick = System.currentTimeMillis();
Intent intent = new Intent(context, TrippyRiepilogo.class);
intent.putExtra("currentTrip", curTrip);
intent.putExtra("currentUser", curUser);
context.startActivity(intent);
}
}
});
}
@Override
public int getItemCount() {
return mDataset.size();
}
}