Предотвращение перемещения макета за определенную границу - PullRequest
1 голос
/ 15 октября 2019

У меня есть LinearLayout с

app:layout_constraintDimensionRatio="1:2"
android:layout_width="match_parent"
app:layout_constraintBottom_toBottomOf="parent"

внутри ConstraintLayout. Выглядит так, как должно быть, если высота экрана в два раза больше ширины экрана. Однако на устройствах, которые шире, верхняя часть моего макета выталкивается за пределы экрана. Тем не менее, я хочу, чтобы верх оставался видимым, а нижняя часть выдвигалась за пределы экрана. Вот как я хочу, чтобы макет работал следующим образом:

1: достаточно длинное устройство, все в порядке:

long device

2: устройство немного шире, но все в порядке:

screen with a 1:2 ratio

3: устройство еще ширеверхняя часть макета все еще должна быть видна, а нижняя должна быть нажата:

even wider screen

1 Ответ

1 голос
/ 16 октября 2019

Решено: Я поместил его в ScrollView, но для того, чтобы app:layout_constraintDimensionRatio также работал, мне нужно было поместить фактическое содержимое в ConstraintLayout в besaid ScrollView:

            <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="bottom"
                android:orientation="vertical">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:id="@+id/layoutBgSnakes"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/imgView"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        app:layout_constraintBottom_toTopOf="@id/imgView2"
                        app:layout_constraintDimensionRatio="1:1"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:srcCompat="@drawable/..." />

                    <ImageView
                        android:id="@+id/imgView2"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintDimensionRatio="1:1"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:srcCompat="@drawable/..." />

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

Примечание: android:fillViewport="true" была ключевой чертой, которая заставляла все работать.

...