ConstraintLayout中的全景ImageView

时间:2019-02-06 09:07:23

标签: android android-layout android-constraintlayout

我有全景视图的实现,在我切换到ConstraintLayout而不是RelativeLayout之前,它的工作效果非常好。现在我遇到的问题是ImageView中心全景图像从设备的左边缘到左边缘而不是中心图像到当前的可见屏幕,所以基本上当陀螺仪向左旋转时它的黑色变为黑色,而当我转到最大时右图像被剪切。

以前我喜欢

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"/>

</RelativeLayout>

现在我有

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <ImageView
        android:id="@+id/image"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

任何想法我在做什么错,或者约束如何以不同的方式处理这个问题?

1 个答案:

答案 0 :(得分:0)

    android:layout_width="0dp"
    android:layout_height="0dp"

这是错误的。如果将其更改为match_parent会发生什么?

相关问题