无法将 RelativeLayout 转换为 ConstraintLayout
Unable to convert RelativeLayout to ConstraintLayout
我有以下代码,我想将 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>
如果您只想要一个 ConstraintLayout 模板,其中包含页眉和页脚以及介于两者之间的 viewpager,那么这里是:
<?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>
您应该可以从那里开始并实现您想要的。
如果您提出任何后续问题,它们将被忽略,因为您的问题包含的信息太少,如果这样做是不公平的。
我有以下代码,我想将 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>
如果您只想要一个 ConstraintLayout 模板,其中包含页眉和页脚以及介于两者之间的 viewpager,那么这里是:
<?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>
您应该可以从那里开始并实现您想要的。
如果您提出任何后续问题,它们将被忽略,因为您的问题包含的信息太少,如果这样做是不公平的。