Как удалить пробел между родителем и ячейкой? - PullRequest
0 голосов
/ 20 июня 2019

У меня есть граница между родителем и моей клеткой. Как удалить это?

Я ищу, но не вижу, в чем проблема в моем коде.

Основной класс:

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

Адаптер:

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:

<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>


Вот экран моего приложения, с рамкой, которую я хочу удалить красным:

https://i.imgur.com/yqPp86o.png

Вот результат, который я хочу получить:

https://i.imgur.com/0revzIK.png

Ответы [ 2 ]

2 голосов
/ 20 июня 2019
android:layout_margin="15dp"

Это ваша проблема, вы добавляете маржу, где вы не хотите, чтобы она была в основной ячейке LinearLayout.

Удалите эту строку, и вы должны быть хорошими.


Примечание:

Поскольку вы используете RecyclerView вместо android:background="@drawable/list_cell_border_main" для добавления границ в ваши ячейки, используйте DividerItemDecoration, посмотрите этот замечательный SO Ответ , которыйпоможет вам сделать именно это.

0 голосов
/ 20 июня 2019

Проблема в android:layout_margin="15dp" в LinearLayout;)

...