Содержимое Textview обрезается справа в макете ограничения - PullRequest
0 голосов
/ 10 апреля 2020

У меня есть макет вида карты с одним imageView на левой стороне и двумя текстовыми представлениями, выровненными по вертикали справа от изображения. Прямо сейчас я получаю проблему, так как текст обрезается в правой части экрана в одном из текстовых изображений. Ниже приведен XML макет, который я использую.

<?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:padding="@dimen/spacing_large"
    tools:context=".ui.profile.GroupProfileActivity"
    android:background="@android:color/background_light">

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/groupCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="@dimen/spacing_normal"
        app:cardElevation="2dp"
        android:elevation="2dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutGroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/groupImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="@+id/layoutGroup"
                app:layout_constraintBottom_toBottomOf="@+id/layoutGroup"
                app:layout_constraintStart_toStartOf="@+id/layoutGroup"
                app:srcCompat="@drawable/ic_group_black_24dp"
                android:paddingLeft="@dimen/spacing_normal"/>

            <!-- Donor type layout -->
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layoutGroupView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="10dp"
                app:layout_constraintLeft_toRightOf="@+id/groupImageView"
                app:layout_constraintTop_toTopOf="@+id/layoutGroup"
                android:layout_marginLeft="@dimen/spacing_normal">

                <TextView
                    android:id="@+id/tvGroupName"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="Demo"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintTop_toTopOf="@+id/layoutGroupView"
                    app:layout_constraintStart_toStartOf="@+id/layoutGroupView"/>

                <TextView
                    android:id="@+id/tvGroupNameLabel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/group_label"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintTop_toBottomOf="@+id/tvGroupName"
                    app:layout_constraintStart_toStartOf="@+id/layoutGroupView"/>
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>

    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/mobileCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/groupCardView"
        android:layout_marginTop="@dimen/spacing_large"
        app:cardElevation="2dp"
        android:elevation="2dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutPhone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/phoneImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="@+id/layoutPhone"
                app:layout_constraintBottom_toBottomOf="@+id/layoutPhone"
                app:layout_constraintStart_toStartOf="@+id/layoutPhone"
                app:srcCompat="@drawable/ic_phone_black_24dp"
                android:paddingLeft="@dimen/spacing_normal"/>

            <!-- Donor type layout -->
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layoutPhoneView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="10dp"
                app:layout_constraintLeft_toRightOf="@+id/phoneImageView"
                app:layout_constraintTop_toTopOf="@+id/layoutPhone"
                android:layout_marginLeft="@dimen/spacing_normal">

                <TextView
                    android:id="@+id/tvPhone"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    tools:text="Demo"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintTop_toTopOf="@+id/layoutPhoneView"
                    app:layout_constraintStart_toStartOf="@+id/layoutPhoneView"/>

                <TextView
                    android:id="@+id/tvPhoneLabel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/phone_label"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintTop_toBottomOf="@+id/tvPhone"
                    app:layout_constraintStart_toStartOf="@+id/layoutPhoneView"/>
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/addressCardView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/mobileCardView"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginTop="@dimen/spacing_large"
        app:cardElevation="2dp"
        android:elevation="2dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutAddress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/addressImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="@+id/layoutAddress"
                app:layout_constraintBottom_toBottomOf="@+id/layoutAddress"
                app:layout_constraintStart_toStartOf="@+id/layoutAddress"
                app:srcCompat="@drawable/ic_home_black_24dp"
                android:paddingLeft="@dimen/spacing_normal"/>

            <!-- Donor type layout -->
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layoutHomeView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="10dp"
                app:layout_constraintLeft_toRightOf="@+id/addressImageView"
                app:layout_constraintTop_toTopOf="@+id/layoutAddress"
                android:layout_marginLeft="@dimen/spacing_normal">

                <TextView
                    android:id="@+id/tvAddress"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    tools:text="Demo"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintTop_toTopOf="@+id/layoutHomeView"
                    app:layout_constraintStart_toStartOf="@+id/layoutHomeView"/>

                <TextView
                    android:id="@+id/tvAddressLabel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/donor_address_hint"
                    android:textSize="@dimen/font_normal"
                    tools:text="sfsfgagaggsggddeggdgagahhahahahahhahahgsgjaaasshhs"
                    android:paddingRight="@dimen/spacing_xxhuge"
                    app:layout_constraintEnd_toEndOf="@+id/layoutHomeView"
                    app:layout_constraintTop_toBottomOf="@+id/tvAddress" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>

, а также добавление скриншота. enter image description here

Пожалуйста, изучите эту проблему, так как я долго борюсь с этой проблемой.

Ответы [ 4 ]

1 голос
/ 10 апреля 2020

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

enter image description here

    <?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:background="@android:color/background_light"
    android:padding="@dimen/spacing_large">

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/groupCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/spacing_normal"
        android:elevation="2dp"
        app:cardElevation="2dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutGroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/groupImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/spacing_normal"
                app:layout_constraintBottom_toBottomOf="@+id/layoutGroup"
                app:layout_constraintStart_toStartOf="@+id/layoutGroup"
                app:layout_constraintTop_toTopOf="@+id/layoutGroup"
                app:srcCompat="@drawable/ic_launcher_background" />

            <!-- Donor type layout -->
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layoutGroupView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/spacing_normal"
                android:orientation="horizontal"
                android:padding="10dp"
                app:layout_constraintStart_toEndOf="@+id/groupImageView"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintLeft_toRightOf="@+id/groupImageView"
                app:layout_constraintTop_toTopOf="@+id/layoutGroup">

                <TextView
                    android:id="@+id/tvGroupName"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="Demo"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintEnd_toEndOf="@+id/layoutGroupView"
                    app:layout_constraintStart_toStartOf="@+id/layoutGroupView"
                    app:layout_constraintTop_toTopOf="@+id/layoutGroupView" />

                <TextView
                    android:id="@+id/tvGroupNameLabel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="group_label"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintEnd_toEndOf="@+id/layoutGroupView"
                    app:layout_constraintStart_toStartOf="@+id/layoutGroupView"
                    app:layout_constraintTop_toBottomOf="@+id/tvGroupName" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>

    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/mobileCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/spacing_large"
        android:elevation="2dp"
        app:cardElevation="2dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/groupCardView">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutPhone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/phoneImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/spacing_normal"
                app:layout_constraintBottom_toBottomOf="@+id/layoutPhone"
                app:layout_constraintStart_toStartOf="@+id/layoutPhone"
                app:layout_constraintTop_toTopOf="@+id/layoutPhone"
                app:srcCompat="@drawable/ic_launcher_background" />

            <!-- Donor type layout -->
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layoutPhoneView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/spacing_normal"
                android:orientation="horizontal"
                android:padding="10dp"
                app:layout_constraintEnd_toEndOf="@+id/layoutPhone"
                app:layout_constraintStart_toEndOf="@+id/phoneImageView"
                app:layout_constraintTop_toTopOf="@+id/layoutPhone">

                <TextView
                    android:id="@+id/tvPhone"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintEnd_toEndOf="@+id/layoutPhoneView"
                    app:layout_constraintStart_toStartOf="@+id/layoutPhoneView"
                    app:layout_constraintTop_toTopOf="@+id/layoutPhoneView"
                    tools:text="Demo" />

                <TextView
                    android:id="@+id/tvPhoneLabel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="phone_label"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintEnd_toEndOf="@+id/layoutPhoneView"
                    app:layout_constraintStart_toStartOf="@+id/layoutPhoneView"
                    app:layout_constraintTop_toBottomOf="@+id/tvPhone" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.card.MaterialCardView>

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/addressCardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/spacing_large"
        android:elevation="2dp"
        app:cardElevation="2dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mobileCardView">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutAddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/addressImageView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="@dimen/spacing_normal"
                app:layout_constraintBottom_toBottomOf="@+id/layoutAddress"
                app:layout_constraintStart_toStartOf="@+id/layoutAddress"
                app:layout_constraintTop_toTopOf="@+id/layoutAddress"
                app:srcCompat="@drawable/ic_launcher_background" />

            <!-- Donor type layout -->
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/layoutHomeView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/spacing_normal"
                android:orientation="horizontal"
                android:padding="10dp"
                app:layout_constraintEnd_toEndOf="@+id/layoutAddress"
                app:layout_constraintStart_toEndOf="@+id/addressImageView"
                app:layout_constraintTop_toTopOf="@+id/layoutAddress">

                <TextView
                    android:id="@+id/tvAddress"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/font_normal"
                    app:layout_constraintEnd_toEndOf="@+id/layoutHomeView"
                    app:layout_constraintStart_toStartOf="@+id/layoutHomeView"
                    app:layout_constraintTop_toTopOf="@+id/layoutHomeView"
                    tools:text="Demo" />

                <TextView
                    android:id="@+id/tvAddressLabel"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:paddingRight="@dimen/spacing_xxhuge"
                    android:text="donor_address_hint"
                    app:layout_constraintEnd_toEndOf="@+id/layoutHomeView"
                    app:layout_constraintTop_toBottomOf="@+id/tvAddress"
                    tools:text="sfsfgagaggsggddeggdgagahhahahahahhahahgsgjaaasshhs" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
0 голосов
/ 10 апреля 2020

сначала: ваш текст не имеет пробелов, а Android Studio - это одно слово. Так что в реальном мире у нас не так длинное слово. Просто добавьте пробел.
Второе: вы создали два контейнера для одной ячейки. Например, вы создаете 1 контейнер, который включает в себя imageView и другой контейнер с textViews. Таким образом, вы можете использовать только 1 контейнер, который будет включать все представления. Потому что ваш «текстовый контейнер» go не отображается (добавлено на картинках). enter image description here

0 голосов
/ 10 апреля 2020

Добавить приложение: layout_constraintEnd_toEndOf = "parent"

В layoutHomeView и addressCardView

0 голосов
/ 10 апреля 2020

Вы установили ширину 0dp. Вместо этого используйте wrap_content:

    android:id="@+id/tvAddressLabel"
                android:layout_width="wrap_content" //here
                android:layout_height="wrap_content"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...