【问题标题】:Move view to edge of camera preview?将视图移动到相机预览的边缘?
【发布时间】:2022-12-18 02:03:31
【问题描述】:

在此布局中,app:layout_constraintBottom_toBottomOf="@+id/preview" 允许我将文本放在相机预览的底部 like this

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/preview_container"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <androidx.camera.view.PreviewView
            android:id="@+id/preview"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="W,4:3"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

        <TextView
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="@+id/preview"
            app:layout_constraintStart_toStartOf="@id/preview"
            android:text="TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST" />

    </androidx.constraintlayout.widget.ConstraintLayout>

但是,如何将该文本移动到相机预览like this 的边缘?

【问题讨论】:

标签: android xml kotlin layout android-camera


【解决方案1】:

如果将文本放在原点并旋转它会怎样?不确定它将如何工作,但值得一试......

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/preview_container"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <androidx.camera.view.PreviewView
            android:id="@+id/preview"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="W,4:3"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"/>

        <TextView
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:rotation="90"
            app:layout_constraintBottom_toBottomOf="@+id/preview"
            app:layout_constraintStart_toStartOf="@id/preview"
            android:text="TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST" />

    </androidx.constraintlayout.widget.ConstraintLayout>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-01-22
  • 1970-01-01
  • 2014-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-10
相关资源
最近更新 更多