gpt4 book ai didi

android - 在按钮的左上侧放置一个徽章气泡

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:33 26 4
gpt4 key购买 nike

我正在尝试将徽章添加到我的 Activity 按钮之一。现在我正在尝试做 xml。带有徽章的按钮应如下所示:

alt text

我已经使用 RelativeLayout 完成了气泡和里面的文本:

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

<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/badge"
android:layout_centerInParent="true"/>

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="2"
android:layout_centerInParent="true" />
</RelativeLayout>

但我找不到将它放在那里并使用相同的 xml 使其在纵向和横向上工作的方法。

Activity中的Buttoms是这样的:

<Button android:id="@+id/new_releases_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/new_releases_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:layout_marginTop="15dp"
android:layout_below="@id/coming_soon_button"
android:onClick="newReleaseClick"
android:layout_centerHorizontal="true" />

<Button android:id="@+id/top_sellers_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/top_sellers_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:layout_marginTop="15dp"
android:layout_below="@id/new_releases_button"
android:onClick="topSellersClick"
android:layout_centerHorizontal="true" />

这是两个资源:

alt text alt text

xml应该怎么做?

编辑:迄今为止最好的方法,但它仍然不起作用:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button android:id="@+id/discounts_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/discounts_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:onClick="discountsClick"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"/>

<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left">

<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/badge"
android:layout_centerInParent="true"/>

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="20"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>

最佳答案

使用 FrameLayout(而不是 RelativeLayout)并将按钮和图像放入其中。

通过以下方式定位图像(带数字的圆圈)和按钮

android:layout_gravity="top|left"
android:layout_marginTop="Xdp"
android:layout_marginLeft="Xdp"

根据自己的喜好。

关于android - 在按钮的左上侧放置一个徽章气泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3541741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com