安卓 : How to write text to specific area in an image

标签 android android-layout android-button android-image

我正在创建一个显示通知编号的图像按钮。这是我的示例图像:

Icon Image

我的目标是在图像中的特定黑色圆圈上写一个数字(1,2..)。我尝试了relativelayout和framelayout,但不认为这是实现结果的可靠方法。原因是边距、填充会因不同的设备尺寸而异。

有什么入门建议吗?

最佳答案

给你:

<FrameLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/pencil">

        <TextView
            android:id="@+id/circle"
            android:layout_width="22dp"
            android:layout_height="22dp"
            android:background="@drawable/circle"
            android:gravity="center"
            android:text="2"
            android:layout_gravity="bottom|right"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:textColor="#FFFFFF"
            android:textSize="12sp" />

    </FrameLayout>

图片:enter image description here enter image description here

输出:

enter image description here

关于安卓 : How to write text to specific area in an image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22040982/

相关文章:

android - Flutter重新运行内部StatefulWidget的initState函数

java - "Only the original thread that created a view hierarchy can touch its views. "如何解决我的情况下的崩溃?

android - View 未通过回调方法更新

android - 如何对齐按钮的用户界面?

Android:如何获取默认应用样式?

android - "BadParcelableException: ClassNotFoundException when unmarshalling <myclass>"使用以 ClassLoader 作为参数的 Parcel.read 方法时

android - Google Inbox 如何显示覆盖键盘的 snackbar ?

Android 工具栏覆盖了一个 fragment

android - 如何使用 drawable 兼容所有屏幕尺寸(idpi、mdpi、hdpi、xhdpi、xxhdpi)

java - 无法解析符号 'setOnClickListener' - Android Studio