我原来的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
不再显示。有没有假设为什么?
答案 0 :(得分:0)
为了获得我想要的布局,我从constraintlayout切换到relativelayout