I'm newbie in Android.
I would like to know if it's possible to put a button or another component over an ImageView. I've tried setting the image as a background image of a LinearLayout, but when I change between landscape and portrait mode, the image porportions are changed.
Thanks a lot.
You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView .
ImageButton has the same property as ImageView . Only one feature is extra, which is, images set through ImageButton are clickable, and actions can be attached with them upon clicking. Just like a button, the setOnClickListener() can be used to set an event listener for click event on this.
An image on the surface of a button is defined within a xml (i.e. layout ) by using src attribute or within java class by using setImageResource() method. We can also set an image or custom drawable in the background of the image button.
ImageView is a control which display image on android and support RGB image, so setting the data of ImageView every period can generate dynamic video.
Don't put the image as a background, you don't have any control on how the image is scaled. Instead, create a RelativeLayout, and put an ImageView as one of the child, and you can place anything (buttons etc) as other RelativeLayout children.
<RelativeLayout ...>
<ImageView (your image) ...>
<Button (the button you want) ... />
</RelativeLayout>
Try this code... it's Help you....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageviewMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="Path "
/>
<Button android:id="@+id/but2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Try this Code .....
In that give paramater in button to set your Button Position....
android:layout_margin or android:layout_alignParent
And also give Path of Image....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With