为什么转换为Constraintlayout会扭曲视图

问题描述 投票:1回答:1

我原来的layout代码如下所示:

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<com.udacity.gradle.builditbigger.Camera.AutoFitTextureView
    android:id="@+id/textureView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3"/>

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/photo_thumbnail_recyclerview"
    android:layout_weight="1"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="snap"
    android:id="@+id/snap"/>

</LinearLayout>

textureView占用了大量的片段。当我切换到具有约束布局时,如下面的代码所示:

<?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"
    android:orientation="vertical">

<com.udacity.gradle.builditbigger.Camera.AutoFitTextureView
    android:id="@+id/textureView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toTopOf="@+id/photo_thumbnail_recyclerview"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    />

<android.support.v7.widget.RecyclerView
    android:id="@+id/photo_thumbnail_recyclerview"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />

<ImageButton
    android:id="@+id/switchcamera_imageButton"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:background="@null"
    android:scaleType="fitCenter"
    app:layout_constraintBottom_toBottomOf="@+id/textureView"
    app:layout_constraintEnd_toEndOf="parent"
    app:srcCompat="@drawable/ic_switch_camera_white_24px" />

<ImageButton
    android:id="@+id/takepicture_imageButton"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:layout_marginBottom="8dp"
    android:background="@null"
    android:scaleType="fitCenter"
    app:layout_constraintBottom_toBottomOf="@+id/textureView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:srcCompat="@drawable/ic_camera_white_24px" />

</android.support.constraint.ConstraintLayout>

纹理view只占用父fragment的宽度,这是我想要的。然而,高度并不比应该位于imagebuttons底部的textureView的高度多。此外,recyclerview不再显示。有没有假设为什么?

android xml android-recyclerview
1个回答
0
投票

为了获得我想要的布局,我从constraintlayout切换到relativelayout

© www.soinside.com 2019 - 2024. All rights reserved.