简体   繁体   中英

Text on half below image

I need to create this view:

在此处输入图片说明

I tried to use coordinator layout, but it's not working, i'm getting that my text is anchored to bottom of image

my try

    <android.support.design.widget.CoordinatorLayout
    android:layout_width="wrap_content"
    android:id="@+id/anchodr"
    android:layout_height="wrap_content">

<ImageView
    android:id="@+id/ticketMainImage"
    android:layout_width="70dp"
    android:src="@drawable/money_icon"
    android:layout_height="110dp" />

    <TextView
        style="@style/TextViewPriceBorder"
        android:id="@+id/ticketPriceText"
        app:layout_anchor="@id/ticketMainImage"
        app:layout_anchorGravity="center|bottom"
        android:text="200"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</android.support.design.widget.CoordinatorLayout>

I know that it's possible to do with relative layout and margins, but what the right way to do it?

try this..

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/anchodr"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true">

    <ImageView
        android:id="@+id/ticketMainImage"
        android:layout_width="match_parent"
        android:layout_height="110dp"
        android:background="#991616"
        android:src="@android:color/transparent" />

    <TextView
        android:id="@+id/ticketPriceText"
        android:layout_marginTop="80dp"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:background="#b7b3b3"
        android:gravity="center_vertical"
        android:textAlignment="center"
        android:text="200"
        app:layout_anchor="@id/ticketMainImage"
        app:layout_anchorGravity="center|bottom" />

</android.support.design.widget.CoordinatorLayout>

Output like this..

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM