Фрагмент не отображается с соответствием родительской высоты - PullRequest
0 голосов
/ 10 января 2019

РЕДАКТИРОВАТЬ: проблема решена, это было связано с дополнительной версией v21, которую нужно было обновить, как показано ниже.

По сути, у меня есть фрагмент с линейным макетом плюс вид карты с макетом ограничения, который я хотел бы заполнить весь экран. В режиме предварительного просмотра в Android Studio все отображается нормально, однако на реальном устройстве оно отображается только до середины экрана. Родительское действие имеет макет «Координатор» и «Вложенное представление прокрутки», которые также имеют высоту match_parent, которая снова показывает прямо в предварительном просмотре, однако желаемое поведение не достигается на устройстве.

Я пытался использовать android:layout_gravity="fill_vertical" (в представлении с вложенной прокруткой), чтобы фон заполнял весь экран, но безрезультатно. Я пробовал также android:fillViewport="true", но это снова не помогает.

Вот код для фрагмента и родительской активности:

Активность родителей

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".PlacesDetailActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="@dimen/elevation_app_bar"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="exitUntilCollapsed"
            >

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_details"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/place_detail_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:background="@color/detail_bckgr"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <FrameLayout
            android:id="@+id/frame_place_detail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

        </FrameLayout>

    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Fragment.xml

 <?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/linear_layout"
    android:orientation="vertical"
    >

    <android.support.v7.widget.CardView
        android:id="@+id/card_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true"
        >

        <android.support.constraint.ConstraintLayout
            android:id="@+id/constraint_layout"
            android:background="@color/detail_bckgr"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            >

            <TextView
                android:id="@+id/place_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:textSize="@dimen/title_size"
                android:layout_margin="@dimen/dimen_margin_general"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="Place 1" />

            <ImageView
                android:id="@+id/place_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/dimen_margin_general"
                app:layout_constraintBottom_toTopOf="@+id/tv_detailed_info"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/place_title"
                app:layout_constraintVertical_bias="0.1"
                tools:src="@drawable/places1_1" />

            <TextView
                android:id="@+id/tv_detailed_info"
                android:layout_margin="@dimen/dimen_margin_general"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:text="@string/lorem_ipsum"
                android:textColor="@color/colorPrimary"
                android:textSize="@dimen/text_description"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/place_image"
                app:layout_constraintVertical_bias="1" />


        </android.support.constraint.ConstraintLayout>

    </android.support.v7.widget.CardView>

</LinearLayout>

Ожидаемый результат - получить высоту match_parent для Nested Scroll View, а цвет фона покрывает весь экран устройства. На самом деле, вид «Вложенный свиток» выглядит как высота "wrap_content".

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...