Reputation: 73
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
the info logo is my png and "about" comes from the button text
Upvotes: 1
Views: 5736
Reputation: 688
<Buttton
android:layout_width="99dp"
android:layout_height="99dp"
android:background = "@drawable/bg" />
bg is your custom image.
Upvotes: 0
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
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"/>
it works for me :)
Upvotes: 5
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
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
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