Android:RelativeLaylout中图像按钮附近的数字

Android:RelativeLaylout中图像按钮附近的数字,android,android-relativelayout,android-imagebutton,Android,Android Relativelayout,Android Imagebutton,因此,我真的想尝试在我的ImageButtons(有点像iPhonebadge通知)附近放上数字,告诉用户该目录中有多少新项目 我考虑这样做的一种方法是在我的按钮上方放置一个图标,然后放置一个文本视图,当没有新项目时,我会编辑该图标以更新编号并隐藏 不幸的是,我不知道如何在布局页面中把东西放在另一个上面:(尝试使用框架布局 尝试使用框架布局 您必须使用FrameLayout将一个项目置于另一个项目之上。您必须使用FrameLayout将一个项目置于另一个项目之上。尝试以下操作: 创建一个包含按钮

因此,我真的想尝试在我的
ImageButtons
(有点像
iPhone
badge通知)附近放上数字,告诉用户该目录中有多少新项目

我考虑这样做的一种方法是在我的
按钮上方放置一个图标,然后放置一个
文本视图
,当没有新项目时,我会编辑该图标以更新编号并隐藏

不幸的是,我不知道如何在布局页面中把东西放在另一个上面:(

尝试使用框架布局

尝试使用框架布局

您必须使用FrameLayout将一个项目置于另一个项目之上。

您必须使用FrameLayout将一个项目置于另一个项目之上。

尝试以下操作:

创建一个包含按钮和文本视图(按顺序)的框架布局。然后文本视图将位于按钮顶部。只需使用框架布局支持的布局参数调整文本视图的位置,直到您满意为止

或者,您可以将当前使用的RelativeLayout替换为FrameLayout,但是您可能需要确保该布局中的所有其他视图仍然正确放置。如果您使用第一个建议,您只需要担心按钮和文本视图。

尝试以下操作:

创建一个包含按钮和文本视图(按顺序)的框架布局。然后文本视图将位于按钮顶部。只需使用框架布局支持的布局参数调整文本视图的位置,直到您满意为止


或者,您可以将当前使用的RelativeLayout替换为FrameLayout,但是您可能需要确保该布局中的所有其他视图仍然正确放置。如果您使用第一个建议,您只需要担心按钮和文本视图。

使用RelativeLayout并将这两个视图对齐到同一个parent

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:layout_alignParentTop="true"></TextView>
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton1"></ImageButton>
</RelativeLayout>

使用RelativeLayout并将两个对象对齐到同一父对象

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:layout_alignParentTop="true"></TextView>
    <ImageButton android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton1"></ImageButton>
</RelativeLayout>