Вложенный LinearLayout не выравнивается с родительским ScrollView? - PullRequest
0 голосов
/ 11 декабря 2018

У меня есть фрагмент с двумя горизонтальными кнопками ( желтый = frag_test_button_container ) внизу моего фрагмента.Я хотел бы использовать оставшуюся область ( красный = frag_test_scrollview ) для ScrollView fragment_test Рекомендуется, чтобы мой ScrollView состоял из одного макета ( бирюзовый = фрагмент_тест_чека ) только.Это, в свою очередь, может иметь дополнительные макеты, как вы можете видеть в прикрепленном файле фрагмента_test.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    tools:context=".ui.TestFragment">

    <ScrollView
        android:id="@+id/fragment_test_scrollview"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/fragment_test_button_container"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent=".84"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:id="@+id/fragment_test_check"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/fragment_test_front_photo_container"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".28"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/fragment_test_front_photo_title"
                    style="@style/myapp_MediumTextStyle"
                    android:layout_width="@dimen/myapp_test_fragment_textview_width"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="24dp"
                    android:text="@string/fragment_test_front_photo_title_text" />

                <ImageView
                    android:id="@+id/fragment_test_front_photo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/fragment_test_back_photo_container"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".28"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/fragment_test_back_photo_title"
                    style="@style/myapp_MediumTextStyle"
                    android:layout_width="@dimen/myapp_test_fragment_textview_width"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="24dp"
                    android:text="@string/fragment_test_back_photo_title_text" />

                <ImageView
                    android:id="@+id/fragment_test_back_photo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical" />

            </LinearLayout>

            <!-- ADDITIONAL DATA -->
            <LinearLayout
                android:id="@+id/fragment_test_data_container"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight=".34"
                android:orientation="vertical"
                android:paddingStart="24dp"
                android:paddingEnd="24dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/fragment_test_value1_label"
                        style="@style/myapp_MediumTextStyle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:text=„Value1^“ />

                    <TextView
                        android:id="@+id/fragment_test_value1_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="24dp" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/fragment_test_value2_label"
                        style="@style/myapp_MediumTextStyle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:text=„Value2“ />

                    <TextView
                        android:id="@+id/fragment_test_value2_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="24dp" />

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/fragment_test_value3_label"
                        style="@style/myapp_MediumTextStyle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:text="Ausstellungsdatum" />

                    <TextView
                        android:id="@+id/fragment_test_value3_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="24dp" />

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/fragment_test_button_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingStart="24dp"
        android:paddingEnd="24dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fragment_test_scrollview">

        <Button
            android:id="@+id/fragment_test_back_button"
            style="@style/myapp_ContinueBackButtonStyle"
            android:layout_width="0dp"
            android:layout_height="@dimen/myapp_continueBackButton_height"
            android:layout_weight="1"
            android:background="@color/myapp_colorPrimary"
            android:text=„back“
            android:textColor="#FFFFFF" />

        <Button
            android:id="@+id/fragment_test_next_button"
            style="@style/myapp_ContinueBackButtonStyle"
            android:layout_width="0dp"
            android:layout_height="@dimen/myapp_continueBackButton_height"
            android:layout_marginStart="24dpVerySmall"
            android:layout_weight="1"
            android:background="@color/myapp_colorPrimary"
            android:text="continue"
            android:textColor="#FFFFFF" />

    </LinearLayout>
</android.support.constraint.ConstraintLayout>
* 1018.match_parent.Мне бы хотелось, чтобы высота бирюзовой зоны была синей.

Почему моя бирюзовая зона болталась пополам синей области?

1 Ответ

0 голосов
/ 11 декабря 2018

Установите android:fillViewport="true" в вашем ScrollView.

fillViewport расширяет высоту содержимого до границ области просмотра, если установлено true.Проще говоря, fillViewport решает, должно ли вложенное содержимое макета соответствовать границам родителя или нет.Таким образом, чтобы вложенный макет соответствовал границе родительского элемента, установите для fillViewport значение true

. Кроме того, layout_gravity для вложенных компонентов должно быть равно 1 или как угодно, что вы определяете в weight_sum родительского макета, тогда как вв вашем случае это 0,90.

...