如何在 XML 中的图像视图上重叠文本视图? [英] How to overlap textview on image view in XML?

查看:34
本文介绍了如何在 XML 中的图像视图上重叠文本视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 android 中有两张图片,一张是图片,另一张是 drawable,这里显示了编号.请让我知道如何将这两件事重叠.

这里是我的代码:

<文本视图android:layout_width="60dp"android:layout_height="60dp"android:id="@+id/circle_tv"android:layout_below="@+id/video_chat_txt"机器人:文本=2"机器人:文本对齐=中心"机器人:重力=中心"android:layout_marginTop="10dp"android:textColor="@color/white"android:textSize="20sp"机器人:layout_centerHorizo​​ntal="true"android:background="@drawable/circle"/>

解决方案

使用此代码并且您必须使用第三个库进行循环文本视图.

<图像视图android:id="@+id/catfish_img"android:layout_width="match_parent"android:layout_height="match_parent"android:src="@drawable/intro1"/><文本视图android:layout_width="20dp"android:layout_height="20dp"android:id="@+id/circle_tv"机器人:文本=2"机器人:文本对齐=中心"机器人:重力=中心"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>

将这些库用于徽章图标

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

这篇关于如何在 XML 中的图像视图上重叠文本视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆