Как добавить маржу только в начале и конце каждой строки в сетке. - PullRequest
0 голосов
/ 06 ноября 2019

Я создал следующий макет для моего RecyclerView и отображаю его в стиле сетки.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:paddingBottom="24dp"
        android:background="@drawable/shadow_player_stats"
        xmlns:app="http://schemas.android.com/apk/res-auto">



    <TextView
            android:id="@+id/tvPlayerStats"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginTop="12dp"
            android:letterSpacing="0.1"
            android:maxLength="4"
            android:maxLines="1"
            android:text="-"
            android:includeFontPadding="false"
            android:textColor="@color/white"
            android:textSize="34dp"
            android:textStyle="bold"
            app:layout_constraintStart_toStartOf="@+id/ivGames"
            app:layout_constraintTop_toTopOf="@+id/ivGames" />

        <TextView
            android:id="@+id/tvLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="12dp"
            android:layout_marginEnd="12dp"
            android:maxLines="2"
            android:lines="2"
            android:text="DATA-TEST"
            android:textAllCaps="true"
            android:textColor="@color/white"
            android:textSize="14dp"
            android:textStyle="normal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@+id/ivGames"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="@+id/ivGames"
            app:layout_constraintTop_toBottomOf="@+id/tvPlayerStats"
            app:layout_constraintVertical_bias="0.0" />


    </androidx.constraintlayout.widget.ConstraintLayout>    

Это создает макет следующего типа.

enter image description here

Но я хочу добавить интервалы в начале и в конце каждой строки, а не между элементами, как, например,

enter image description here

Ответы [ 2 ]

0 голосов
/ 10 ноября 2019

Попробуйте решение ниже.

Это мой пользовательский макет, содержащий TextView my_custom_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/myCustomTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:textColor="@android:color/holo_green_dark"
        android:textSize="16sp"
        android:textStyle="bold" />

</LinearLayout>

В приведенном выше коде вы можете видеть, что я установил paddingTopи paddingBottom в TextView, поэтому он будет генерировать макет примерно так:

enter image description here

Теперь, когда я просто хочу установить больше поля / отступа на ,начало и конец только в режиме recyclerview , я должен установить ниже свойства в коде recyclerview xml.

android:clipToPadding="false"
android:paddingTop="15dp"
android:paddingBottom="15dp"

, который сгенерирует макет примерно так:

enter image description here

ПРИМЕЧАНИЕ. Я уменьшил отступы из моего textView

0 голосов
/ 08 ноября 2019

Добавление начального / левого и конечного / правого отступа в окне рециркуляции

Попробуйте это

  <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/draft_recylcerview"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" 
                            android:paddingLeft="@dimen/margin_10"
                            android:paddingRight="@dimen/margin_10"/>
...