Невозможно преобразовать RelativeLayout в ConstraintLayout - PullRequest
0 голосов
/ 27 декабря 2018

У меня есть следующий код, и я хочу преобразовать RelativeLayout в ConstraintLayout и хочу, чтобы он отображался точно так же.Однако тег ViewPager не располагается в центре, как ожидалось.Я хочу, чтобы следующий код был в макете ограничения, но не смог его достичь.Я преобразовал layout_above в layout_constraintTop_toTopOf и тому подобное, но не могу заставить его работать хорошо.Было бы здорово, если бы вы могли поделиться некоторыми примерами или советами!Я хотел бы услышать от вас!

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <LinearLayout
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

            <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true">

                <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:adjustViewBounds="true"
                        android:scaleType="fitXY"
                        android:src="@drawable/d"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintBottom_toBottomOf="parent"/>

            </androidx.constraintlayout.widget.ConstraintLayout>

            <View android:layout_width="0dp"
                  android:layout_weight="1"
                  android:layout_height="1dp"/>
        </LinearLayout>
        <androidx.viewpager.widget.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@id/footer"
                android:layout_below="@id/header"
                android:overScrollMode="never">
        </androidx.viewpager.widget.ViewPager>

        <LinearLayout
                android:id="@+id/footer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="vertical">
            <include layout="@layout/pagerlayout"/>

        </LinearLayout>
    </RelativeLayout>

1 Ответ

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

Если вам просто нужен шаблон ConstraintLayout с верхним и нижним колонтитулами с промежуточным просмотрщиком, то здесь вы идете:

<?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=".MainActivity">

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:orientation="horizontal"
        app:layout_constraintTop_toTopOf="parent">


    </LinearLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/footer"
        android:layout_below="@id/header"
        android:layout_marginTop="8dp"
        android:overScrollMode="never"
        app:layout_constraintBottom_toTopOf="@+id/footer"
        app:layout_constraintTop_toBottomOf="@+id/header"></androidx.viewpager.widget.ViewPager>

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent">
        <!-- include layout="@layout/pagerlayout"/ -->

    </LinearLayout>

    </android.support.constraint.ConstraintLayout>

Вы должны иметь возможность начать оттуда и получить то, что вы хотите.

Если вы зададите какие-либо дополнительные вопросы, они будут проигнорированы, поскольку в вашем вопросе так мало информации, что, если это будет несправедливо, сделайте это.

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