Reputation: 14612
I try to put a regular button inside an image in android XML. How can it be done? I tried something like this:
<ImageView .......
<Button .... />
</ImageView>
where the dots represent code. Apparently this is not the way because the platform threw an exception.
Can anyone help?
Upvotes: 2
Views: 1891
Reputation: 9005
Use relative layout to insert button on the image.
your image should be given in background tag of RelativeLayout.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/list_nav"
>
<Button
android:layout_width="63dp"
android:layout_height="36dp"
android:id="@+id/mapbutton"
android:layout_marginTop="7dp"
android:layout_marginLeft="4dp"
android:layout_alignParentLeft="true"
/>
this Example adds button on left side of the image since i used layout_alignParentLeft="true"
Upvotes: 6
Reputation: 2350
You can use FrameLayout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="@+id/myImage"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/icon" />
<Button android:id="@+id/myButton"
android:layout_width="150dip"
android:layout_height="150dip"
android:text="My Button"/>
</FrameLayout>
You don't write why you need image and button. Do you know about ImageButton?
Upvotes: 3
Reputation: 6186
@Uriel Frankel you may try creating a custom ImageView either.Here is a post regarding Creating Custom ImageView.
Hope it helps.
Upvotes: 2