简体   繁体   中英

How to overlap textview on image view in XML?

I have two images in android where one is image and another one is drawable which show the numbering here. please let me know how could be possible to overlap both these things. 在此处输入图片说明

here my code:

<ImageView
    android:id="@+id/catfish_img"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/icon_cat_fish" />

<TextView
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:id="@+id/circle_tv"
    android:layout_below="@+id/video_chat_txt"
    android:text="2"
    android:textAlignment="center"
    android:gravity="center"
    android:layout_marginTop="10dp"
    android:textColor="@color/white"
    android:textSize="20sp"
    android:layout_centerHorizontal="true"
    android:background="@drawable/circle"/>

Use this code and You have to use third library for circular text view.

<RelativeLayout
    android:layout_width="100dp"
    android:layout_height="100dp">
    <ImageView
        android:id="@+id/catfish_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/intro1" />

    <TextView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:id="@+id/circle_tv"
        android:text="2"
        android:textAlignment="center"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:textColor="@color/white"
        android:textSize="20sp"
        android:background="@drawable/circle"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="15dp"

        />
    <!--android:background="@drawable/circle"-->
</RelativeLayout>

Use these libraries for badge icon http://www.exceptionbound.com/programming-tut/android-tutorial/add-badge-item-count-to-icon-android-app-android-studio

https://github.com/arturogutierrez/Badges

https://github.com/mikepenz/Android-ActionItemBadge

https://github.com/jgilfelt/android-viewbadger

https://github.com/leolin310148/ShortcutBadger

Output will be like this

在此处输入图片说明

Place both in a relative layout and then align the text as necessary within the relative layout.

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
            android:id="@+id/catfish_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon_cat_fish" />

        <TextView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:id="@+id/circle_tv"
            android:layout_below="@+id/video_chat_txt"
            android:text="2"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_marginTop="10dp"
            android:textColor="@color/white"
            android:textSize="20sp"
            android:layout_centerHorizontal="true"
            android:background="@drawable/circle"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            />

</RelativeLayout>

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