I want to put image over button

I want to put png image over button i tried android:background but the png takes all the button what i want exactly is to use the logo png over button like this

enter image description here

the info logo is my png and "about" comes from the button text

Upvotes: 1

Views: 5736

Answers (6)

Shivputra N
Shivputra N

Reputation: 688

 <Buttton
        android:layout_width="99dp"
        android:layout_height="99dp"
        android:background = "@drawable/bg" />

bg is your custom image.

Upvotes: 0

Kirtan
Kirtan

Reputation: 1812

you can use

android:drawableTop 

to put drawable at top of Button and use appropriate padding to make it position well.

Upvotes: 0

Rikkert09
Rikkert09

Reputation: 190

u can use this:

android:drawableTop="@drawable/SomeIcon"

so then you get this:

<Button
android:id="@+id/damage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="about"
android:drawableTop="@android:drawable/ic_menu_info_details"/>

enter image description here

it works for me :)

Upvotes: 5

schnill
schnill

Reputation: 955

Take a RelativeLayout, place ImageView inside it. Now set onClickListener on RelativeLayout. By this way you can create more complex buttons.

<RelativeLayout android:id="@+id/your_btn_id" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

Upvotes: 1

Benjamin RD
Benjamin RD

Reputation: 12034

You can check this thread Basically, you can use:

<ImageButton
    android:id="@+id/ImageButton01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/album_icon"
    android:background="@drawable/round_button" />

As the thread says.

Upvotes: 1

RPB
RPB

Reputation: 16320

You can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_text" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/my_drawable"
        android:scaleType="fitCenter"/>
</FrameLayout>

In this instance, the ImageView would be drawn on top of the Button, along the bottom center of the Button.

Upvotes: 1

Related Questions