Почему мой макет выглядит так? Вот мой XML-файл

#android #xml #android-layout

#Android #xml #android-layout

Вопрос:

Вот мой

Изображение устройства

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

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@ id/item_linerLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dp">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="10dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="10dp">

            <TextView
                android:id="@ id/item_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1"
                android:textSize="36sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@ id/item_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Title"
                app:layout_constraintStart_toEndOf="@ id/item_id"
                app:layout_constraintTop_toTopOf="@ id/item_id" />

            <TextView
                android:id="@ id/item_AuthorName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Author"
                app:layout_constraintStart_toStartOf="@ id/item_title"
                app:layout_constraintTop_toBottomOf="@ id/item_title" />

            <TextView
                android:id="@ id/item_pages"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="3dp"
                android:text="100"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.cardview.widget.CardView>

</LinearLayout>
  

Комментарии:

1. Можете ли вы сказать мне, что перекрывается?

2. Сэр, последний идентификатор TextView-=»@ id/item_pages» перекрывается.

3. Вы ограничили последнее текстовое представление родительским. Измените ограничение на app:layout_constraintTop_toBottomOf=»@ id/item_AuthorName» .

Ответ №1:

Попробуйте использовать android:fitsSystemWindows="true" в своем корневом макете (в вашем случае LinearLayout). Я рекомендую вам прочитать эту статью, чтобы понять перекрытие системы. Надеюсь, это поможет)

Комментарии:

1. Я думал, вы хотите отключить перекрытие строки состояния, для TextView (item_pages) Просто используйте app:layout_constraintBottom_toBottomOf=»родительский» app:layout_constraintEnd_toEndOf=»родительский». приложение:layout_constraintTop_toTopOf=»родительский»

Ответ №2:

Я удалил избыточный LinearLayout родительский элемент и создал CardView родительский элемент. Также ваш TextView с id item_pages не перекрывается.

 <androidx.cardview.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    app:cardElevation="10dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <TextView
            android:id="@ id/item_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"
            android:textSize="36sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@ id/item_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:text="Title"
            app:layout_constraintBottom_toTopOf="@id/item_AuthorName"
            app:layout_constraintStart_toEndOf="@ id/item_id" />

        <TextView
            android:id="@ id/item_AuthorName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:text="Author"
            app:layout_constraintBottom_toBottomOf="@id/item_id"
            app:layout_constraintStart_toStartOf="@ id/item_title" />

        <TextView
            android:id="@ id/item_pages"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="3dp"
            android:text="100"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>