isep
isep

Reputation: 713

Android: numbers near ImageButtons in RelativeLaylout

So, I really want to try and put numbers near my ImageButtons (kinda like the iPhone badge notifications) to tell the user how many new items are in that directory.

One way I was thinking of doing this was to put an icon above my Button and then put a TextView that I would edit to update the number and hide when there were no new items.

Unfortunately, I can't figure out how to put things on top of one another in the layout page. :(

Upvotes: 1

Views: 554

Answers (4)

Ben Williams
Ben Williams

Reputation: 6167

Use RelativeLayout and align both things to the same 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>

Upvotes: 1

TofferJ
TofferJ

Reputation: 4784

Try this:

Create a FrameLayout that contains the Button and the TextView (in that order). Then the TextView will end up on top of your button. Just use layout parameters supported by the FrameLayout to adjust the position of the TextView until you are happy.

Or you could replace the RelativeLayout that you are using now with a FrameLayout, but then you probably need to make sure that all other views in that layout still are placed correctly. If you go with the first suggestion you only need to worry about the button and the text view.

Upvotes: 1

Sujit
Sujit

Reputation: 10632

you have to use FrameLayout to put one item over another .

Upvotes: 1

Related Questions