0

I have a border between parent and my cell. How to delete it ?

I search but I don't find where is the problem in my code.

Main class :

final RecyclerView rv = (RecyclerView) findViewById(R.id.contentMain_rv_1);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setAdapter(new MainActivityRecyclerViewAdapter());

Adapter :

public class MainActivityRecyclerViewAdapter extends RecyclerView.Adapter<MainActivityRecyclerViewAdapter.MyViewHolder> {

    private final List<Pair<String, String>> characters = Arrays.asList(
            Pair.create("Lyra Belacqua", "01/01/2001"),
            Pair.create("Pantalaimon", "01/01/2002."),
            Pair.create("Roger Parslow", "01/01/2003"),
            Pair.create("Lord Asriel", "01/01/2004"),
            Pair.create("Marisa Coulter", "01/01/2005."),
            Pair.create("Iorek Byrnison", "01/01/2006."),
            Pair.create("Serafina Pekkala", "01/01/2007."),
            Pair.create("Lee Scoresby", "01/01/2008."),
            Pair.create("Ma Costa", "01/01/2009"),
            Pair.create("John Faa", "01/01/2010")
    );

    @Override
    public int getItemCount() {
        return characters.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.list_cell_main, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Pair<String, String> pair = characters.get(position);
        holder.display(pair);
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        private final TextView name;
        private final TextView description;

        private Pair<String, String> currentPair;

        public MyViewHolder(final View itemView) {
            super(itemView);

            name = ((TextView) itemView.findViewById(R.id.name));
            description = ((TextView) itemView.findViewById(R.id.description));

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new AlertDialog.Builder(itemView.getContext())
                            .setTitle(currentPair.first)
                            .setMessage(currentPair.second)
                            .show();
                }
            });
        }

        public void display(Pair<String, String> pair) {
            currentPair = pair;
            name.setText(pair.first);
            description.setText(pair.second);
        }
    }

XML cell :

<LinearLayout 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:layout_margin="15dp"
    android:background="@drawable/list_cell_border_main"
    android:orientation="vertical">


    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@android:drawable/ic_dialog_info" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginStart="32dp"
            android:layout_marginTop="8dp"
            android:ellipsize="end"
            android:lines="1"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="22sp"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@+id/imageView2"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="Description"></TextView>

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginStart="32dp"
            android:layout_marginTop="8dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            app:layout_constraintStart_toEndOf="@+id/imageView2"
            app:layout_constraintTop_toBottomOf="@+id/description"
            tools:text="Personnage"></TextView>

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@android:drawable/ic_menu_info_details" />
    </android.support.constraint.ConstraintLayout>

XML content_main :

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activities.MainActivity"
    tools:showIn="@layout/app_bar_main">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/contentMain_rv_1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>


Here is a screen of my app, with the border I want to delete in red :

https://i.stack.imgur.com/Gi5Mj.png

Here the result I want to have :

https://i.stack.imgur.com/2aQT1.png

VickeS
  • 29
  • 6
  • 2
    In your `LinearLayout` of the `cell layout file` remove the `android:layout_margin="15dp"`. You may also want to remove the `android:background="@drawable/list_cell_border_main"` and replace it with just the background color, because the separation lines between each row / cell can be customized with `DividerItemDecoration` – Vall0n Jun 20 '19 at 08:29
  • You have `android:layout_margin="15dp"` in your cell xml. Remove that it should work. – Harsh Karanpuria Jun 20 '19 at 08:31
  • Thank's. It's the solution for my problem – VickeS Jun 20 '19 at 08:32

2 Answers2

2
android:layout_margin="15dp"

There's your problem, you are adding margin, where you don't want it in your cell's main LinearLayout.

Remove that line and you should be good.


Side Note:

Since you are using RecyclerView instead of using android:background="@drawable/list_cell_border_main" to add borders to your cells, use DividerItemDecoration check out this great SO Answer which guides you on how to do exactly that.

Abbas
  • 3,529
  • 5
  • 36
  • 64
  • 1
    @Vich glad it worked :) you should mark the question as correct so anyone else who finds this question knows the correct answer. – Abbas Jun 20 '19 at 08:35
  • Yes, i do that ;) – VickeS Jun 20 '19 at 08:37
  • @Vich check out [How does accepting an Answer Work](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – Abbas Jun 20 '19 at 08:40
0

The problem is on android:layout_margin="15dp" in the LinearLayout ;)

Van Diest
  • 117
  • 7