【发布时间】:2017-12-11 04:24:16
【问题描述】:
我原来的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的宽度,这正是我想要的。但是,高度不会比应该位于textureView 底部的imagebuttons 的高度高多少。此外,recyclerview 不再显示。有人对为什么有假设吗?
【问题讨论】:
标签: android xml android-recyclerview