0

I have a layout with an Imageview and a Textview. Imageview will occupy all the size of the layer, and Textview will be on top of the image, and always at the same relative distance to the corners of the image. For instance, I want the Textview to be at a position such that its y position is 1/3 of the height of the Imageview. How can I do this?

I'm open to any kind of layout you consider is necessary. Please avoid third libraries or deprecated android methods.

Learning from masters
  • 2,032
  • 3
  • 29
  • 42
  • 1
    [ConstraintLayout with guidelines](https://stackoverflow.com/questions/37318228/how-to-make-constraintlayout-work-with-percentage-values) would be an option – Zain Dec 25 '22 at 23:12

1 Answers1

0

Thank you @Zain. Here there is the example using a SVG image!

<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>
Learning from masters
  • 2,032
  • 3
  • 29
  • 42