簡體   English   中英

將 textview 放在 imageview 之上,始終與圖像保持相同的相對關系 position

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM