Как мне избавиться от этого разрыва между панелью инструментов и представлением ресайклера? - PullRequest
0 голосов
/ 08 мая 2020

Я новичок в программировании на android. Хотел бы получить некоторые рекомендации и помощь, чтобы избавиться от этого разрыва между панелью инструментов и моим представлением об утилизации. Прочтите некоторые рецензии на людей, которые столкнулись с той же проблемой, но большинство из них включали «Макет координатора» или «layout_gravity». Однако в моем коде их не было. Пробовал много других способов, но не смог заставить его работать.

View the Image here!

Вот изображение, основанное на коде! Встроенное изображение показывает лучший контраст для зазора. Извините, моя учетная запись пока не позволяет встраивать фотографии.

  1. Вот мой код для родительского представления ресайклера.

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvProfile"
        android:layout_width="403dp"
        android:layout_height="match_parent"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp" />
    

  2. Вот код для моего индивидуального макета элемента.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/profileImage"
        android:layout_width="111dp"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="29dp"
        android:background="@drawable/profile"></ImageView>

    <TextView
        android:id="@+id/profileUserName"
        android:layout_width="wrap_content"
        android:layout_height="29dp"
        android:layout_alignParentTop="true"
        android:layout_marginStart="4dp"
        android:layout_marginTop="1dp"
        android:layout_toEndOf="@+id/profileImage"
        android:text="User Name"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="25sp"></TextView>

    <Button
        android:id="@+id/changeProfilePicture"
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:layout_below="@+id/profileUserName"
        android:layout_marginStart="4dp"
        android:layout_marginTop="8dp"
        android:layout_toEndOf="@+id/profileImage"
        android:background="@color/zxing_transparent"
        android:text="Change Profile Picture"
        android:textAllCaps="false"
        android:textColor="@color/textColorLight"
        android:textSize="20sp"
        android:textStyle="normal"></Button>

    <Button
        android:id="@+id/changePasswordBtn"
        android:layout_width="wrap_content"
        android:layout_height="23dp"
        android:layout_below="@+id/changeProfilePicture"
        android:layout_marginStart="6dp"
        android:layout_marginTop="6dp"
        android:layout_toEndOf="@+id/profileImage"
        android:background="@color/zxing_transparent"
        android:text="Change Password"
        android:textAllCaps="false"
        android:textColor="@color/textColorLight"
        android:textSize="20sp"
        android:textStyle="normal"></Button>

    <TextView
        android:id="@+id/accountbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/profileImage"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="1dp"
        android:layout_marginTop="-1dp"
        android:layout_marginEnd="0dp"
        android:background="@color/primarylighest"
        android:padding="5dp"
        android:paddingStart="30dp"
        android:text="Account"
        android:textColor="@color/colorPrimary"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/pointsTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/accountbar"
        android:layout_alignParentStart="true"
        android:layout_marginStart="35dp"
        android:layout_marginTop="4dp"
        android:text="Points"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="25sp"></TextView>

    <TextView
        android:id="@+id/pointsDisplay"
        android:layout_width="157dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/accountbar"
        android:layout_marginStart="131dp"
        android:layout_marginTop="6dp"
        android:layout_toEndOf="@+id/pointsTxt"
        android:text="42 Points"
        android:textColor="@color/textColorLight"
        android:textSize="20sp"></TextView>

    <TextView
    android:id="@+id/orderHistoryTxt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/pointsTxt"
    android:layout_alignParentStart="true"
    android:layout_marginStart="35dp"
    android:layout_marginTop="0dp"
    android:text="Order History"
    android:textColor="@color/colorPrimaryDark"
    android:textSize="25sp"></TextView>

    <Button
        android:id="@+id/orderHistBtn"
        android:layout_width="33dp"
        android:layout_height="28dp"
        android:layout_below="@+id/pointsDisplay"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="178dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="15dp"
        android:layout_toEndOf="@+id/orderHistoryTxt"
        android:background="@drawable/profile_back"
        android:rotation="180"></Button>

    <TextView
    android:id="@+id/txtExpenseTracker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/orderHistoryTxt"
    android:layout_alignParentStart="true"
    android:layout_marginStart="35dp"
    android:layout_marginTop="1dp"
    android:text="Expense Tracker"
    android:textColor="@color/colorPrimaryDark"
    android:textSize="25sp"></TextView>


    <Button
        android:layout_width="32dp"
        android:layout_height="31dp"
        android:layout_below="@+id/pointsDisplay"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="141dp"
        android:layout_marginTop="44dp"
        android:layout_marginEnd="16dp"
        android:layout_toEndOf="@+id/txtExpenseTracker"
        android:background="@drawable/profile_back"
        android:rotation="180"></Button>

    <TextView
    android:id="@+id/txtCurrencyConvertor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/orderHistoryTxt"
    android:layout_alignParentStart="true"
    android:layout_marginStart="35dp"
    android:layout_marginTop="37dp"
    android:text="Currency Convertor"
    android:textColor="@color/colorPrimaryDark"
    android:textSize="25sp"></TextView>

    <Button
        android:layout_width="30dp"
        android:layout_height="24dp"
        android:layout_below="@+id/pointsDisplay"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="176dp"
        android:layout_marginTop="210dp"
        android:layout_marginEnd="16dp"
        android:layout_toEndOf="@+id/txtPrivacyPolicy"
        android:background="@drawable/profile_back"
        android:rotation="180"></Button>

    <TextView
        android:id="@+id/othersbar"
        android:layout_width="410dp"
        android:layout_height="46dp"
        android:layout_below="@+id/profileImage"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="1dp"
        android:layout_marginTop="206dp"
        android:layout_marginEnd="0dp"
        android:background="@color/primarylighest"
        android:padding="5dp"
        android:paddingStart="30dp"
        android:text="Others"
        android:textColor="@color/colorPrimary"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/txtShare"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/orderHistoryTxt"
        android:layout_alignParentStart="true"
        android:layout_marginStart="35dp"
        android:layout_marginTop="140dp"
        android:text="Share Krysjay with friends"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="25sp"></TextView>

    <Button
        android:layout_width="32dp"
        android:layout_height="31dp"
        android:layout_below="@+id/othersbar"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="37dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="16dp"
        android:layout_toEndOf="@+id/txtShare"
        android:background="@drawable/profile_back"
        android:rotation="180"></Button>

    <TextView
        android:id="@+id/txtPrivacyPolicy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/orderHistoryTxt"
        android:layout_alignParentStart="true"
        android:layout_marginStart="35dp"
        android:layout_marginTop="172dp"
        android:text="Privacy Policy"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="25sp"></TextView>

    <Button
        android:layout_width="32dp"
        android:layout_height="31dp"
        android:layout_below="@+id/othersbar"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="110dp"
        android:layout_marginTop="-97dp"
        android:layout_marginEnd="15dp"
        android:layout_toEndOf="@+id/txtCurrencyConvertor"
        android:background="@drawable/profile_back"
        android:rotation="180"></Button>

    <TextView
        android:id="@+id/txtTermsCons"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/orderHistoryTxt"
        android:layout_alignParentStart="true"
        android:layout_marginStart="35dp"
        android:layout_marginTop="205dp"
        android:text="Terms &amp; Conditions"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="25sp"></TextView>

    <Button
        android:layout_width="32dp"
        android:layout_height="31dp"
        android:layout_below="@+id/othersbar"
        android:layout_alignParentEnd="true"
        android:layout_marginStart="105dp"
        android:layout_marginTop="66dp"
        android:layout_marginEnd="17dp"
        android:layout_toEndOf="@+id/txtTermsCons"
        android:background="@drawable/profile_back"
        android:rotation="180"></Button>

    <Button
        android:id="@+id/signOutBtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtPrivacyPolicy"
        android:layout_alignParentStart="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="27dp"
        android:layout_marginBottom="132dp"
        android:background="@color/zxing_transparent"
        android:outlineAmbientShadowColor="@color/colorPrimaryDark"
        android:paddingStart="30dp"
        android:text="Sign Out"
        android:textAlignment="textStart"
        android:textAllCaps="false"
        android:textColor="@color/colorPrimary"
        android:textSize="25sp" />

</RelativeLayout>
</ScrollView>
</RelativeLayout>

Ответы [ 2 ]

1 голос
/ 08 мая 2020

Вы пытались удалить эту строку кода из вашего imageView?

android:layout_marginTop="67dp"
0 голосов
/ 08 мая 2020
<RelativeLayout
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">
<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/profileImage"
            android:layout_width="111dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:background="@drawable/profile"></ImageView>

        <TextView
            android:id="@+id/accountbar"
            android:layout_width="410dp"
            android:layout_height="46dp"
            android:background="@color/primarylighest"
            android:padding="5dp"
            android:paddingStart="30dp"
            android:text="Account"
            android:textColor="@color/colorPrimary"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/profileImage"/>

        <TextView
            android:id="@+id/profileUserName"
            android:layout_width="wrap_content"
            android:layout_height="29dp"
            android:text="User Name"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@id/accountbar"
            app:layout_constraintTop_toBottomOf="@id/profileImage"></TextView>

        <Button
            android:id="@+id/changeProfilePicture"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_marginStart="4dp"
            android:background="@color/zxing_transparent"
            android:text="Change Profile Picture"
            android:textAllCaps="false"
            android:textColor="@color/textColorLight"
            android:textSize="20sp"
            android:textStyle="normal"
            app:layout_constraintEnd_toStartOf="@id/pointsDisplay"
            app:layout_constraintHorizontal_bias="0.516"
            app:layout_constraintStart_toEndOf="@id/pointsTxt"
            app:layout_constraintTop_toBottomOf="@id/accountbar"></Button>

        <Button
            android:id="@+id/changePasswordBtn"
            android:layout_width="wrap_content"
            android:layout_height="23dp"
            android:layout_marginStart="6dp"
            android:layout_marginTop="6dp"
            android:background="@color/zxing_transparent"
            android:text="Change Password"
            android:textAllCaps="false"
            android:textColor="@color/textColorLight"
            android:textSize="20sp"
            android:textStyle="normal"
            app:layout_constraintEnd_toStartOf="@id/pointsDisplay"
            app:layout_constraintStart_toEndOf="@id/pointsTxt"
            app:layout_constraintTop_toBottomOf="@id/changeProfilePicture"></Button>

        <TextView
            android:id="@+id/pointsTxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="8dp"
            android:text="Points"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/accountbar"></TextView>

        <TextView
            android:id="@+id/pointsDisplay"
            android:layout_width="157dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="131dp"
            android:layout_marginTop="20dp"
            android:layout_marginEnd="15dp"
            android:text="42 Points"
            android:textColor="@color/textColorLight"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/pointsTxt"
            app:layout_constraintTop_toBottomOf="@id/accountbar"></TextView>

        <TextView
            android:id="@+id/orderHistoryTxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="4dp"
            android:text="Order History"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/pointsTxt"></TextView>


        <Button
            android:id="@+id/orderHistBtn"
            android:layout_width="33dp"
            android:layout_height="28dp"
            android:layout_marginEnd="15dp"
            android:background="@drawable/profile_back"
            android:rotation="180"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@id/orderHistoryTxt"
            app:layout_constraintTop_toBottomOf="@id/changePasswordBtn"></Button>

        <TextView
            android:id="@+id/txtExpenseTracker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="4dp"
            android:text="Expense Tracker"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/orderHistoryTxt"></TextView>

        <Button
            android:id="@+id/btnExpenseTracker"
            android:layout_width="32dp"
            android:layout_height="31dp"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="15dp"
            android:background="@drawable/profile_back"
            android:rotation="180"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@id/txtExpenseTracker"
            app:layout_constraintTop_toBottomOf="@id/orderHistBtn"></Button>

        <TextView
            android:id="@+id/txtCurrencyConvertor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="4dp"
            android:text="Currency Convertor"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/txtExpenseTracker"></TextView>

        <Button
            android:id="@+id/button"
            android:layout_width="30dp"
            android:layout_height="24dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="15dp"
            android:background="@drawable/profile_back"
            android:rotation="180"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@id/txtPrivacyPolicy"
            app:layout_constraintTop_toBottomOf="@id/btnShareWithFriends"></Button>

        <TextView
            android:id="@+id/othersbar"
            android:layout_width="410dp"
            android:layout_height="46dp"
            android:layout_marginTop="4dp"
            android:background="@color/primarylighest"
            android:padding="5dp"
            android:paddingStart="30dp"
            android:text="Others"
            android:textColor="@color/colorPrimary"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/txtCurrencyConvertor" />

        <TextView
            android:id="@+id/txtShare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="4dp"
            android:text="Share Krysjay with friends"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/othersbar"></TextView>

        <Button
            android:id="@+id/btnShareWithFriends"
            android:layout_width="32dp"
            android:layout_height="31dp"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="15dp"
            android:background="@drawable/profile_back"
            android:rotation="180"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@id/txtShare"
            app:layout_constraintTop_toBottomOf="@id/othersbar"></Button>

        <TextView
            android:id="@+id/txtPrivacyPolicy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="4dp"
            android:text="Privacy Policy"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/txtShare"></TextView>

        <Button
            android:id="@+id/btnCurrencyCovertor"
            android:layout_width="32dp"
            android:layout_height="31dp"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="15dp"
            android:background="@drawable/profile_back"
            android:rotation="180"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@id/txtCurrencyConvertor"
            app:layout_constraintTop_toBottomOf="@id/btnExpenseTracker"></Button>

        <TextView
            android:id="@+id/txtTermsCons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="35dp"
            android:layout_marginTop="4dp"
            android:text="Terms &amp; Conditions"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/txtPrivacyPolicy"></TextView>

        <Button
            android:id="@+id/btnTermsCond"
            android:layout_width="32dp"
            android:layout_height="31dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="15dp"
            android:background="@drawable/profile_back"
            android:rotation="180"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toEndOf="@+id/txtTermsCons"
            app:layout_constraintTop_toBottomOf="@+id/button"></Button>

        <Button
            android:id="@+id/signOutBtn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txtPrivacyPolicy"
            android:layout_alignParentStart="true"
            android:layout_marginTop="4dp"
            android:background="@color/zxing_transparent"
            android:outlineAmbientShadowColor="@color/colorPrimaryDark"
            android:paddingStart="30dp"
            android:text="Sign Out"
            android:textAlignment="textStart"
            android:textAllCaps="false"
            android:textColor="@color/colorPrimary"
            android:textSize="25sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/txtTermsCons" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

...