[英]Put a textview on top of an imageview always at the same relative position to the image
我有一个 Imageview 和 Textview 的布局。Imageview 将占据图层的所有大小,而 Textview 将位于图像的顶部,并且始终与图像的角落保持相同的相对距离。 例如,我希望 Textview 位于 position,这样它的y position 是 Imageview 高度的 1/3。我该怎么做?
我对您认为必要的任何布局持开放态度。 请避免第三方库或弃用的 android 方法。
谢谢@Zain。 这里有一个使用 SVG 图像的例子!
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/parent_layout"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/img_example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintHeight_max="200dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="@drawable/photo" />
<TextView
android:id="@+id/lbl_example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.80"
app:layout_constraintHorizontal_bias="0.5"
android:text="Example"
android:textSize="20sp" />
</androidx.constraintlayout.widget.ConstraintLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.