Riskhan
Riskhan

Reputation: 4470

How to show stretch image in ImageButton in android

In my ui, i use image button for various actions. In xml file as follows

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ImageButton
    android:id="@+id/homebtn"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Home"
    android:scaleType="fitCenter"
    android:src="@drawable/homebutton"
    android:onClick="onHomeBtn"
    />

<ImageButton
    android:id="@+id/backbtn"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Back"
    android:scaleType="fitCenter"
    android:src="@drawable/backbutton"
    android:onClick="onBackBtn"
    />

<TextSwitcher
    android:id="@+id/infomsg"
    android:layout_width="550dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" />

<ImageButton
    android:id="@+id/exitbtn"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Exit"
    android:scaleType="fitCenter"
    android:onClick="onExitBtn"
    android:src="@drawable/exitbutton"
    />

image shows output of ui. Images in the button is not fully covered. I not need border in the button. How is possible ?

enter image description here

Upvotes: 0

Views: 733

Answers (2)

Avijit
Avijit

Reputation: 3824

This will help you.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ImageButton
    android:id="@+id/homebtn"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Home"
    android:scaleType="fitCenter"
    android:background="@drawable/homebutton"
    android:onClick="onHomeBtn"
    />

<ImageButton
    android:id="@+id/backbtn"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Back"
    android:scaleType="fitCenter"
    android:background="@drawable/backbutton"
    android:onClick="onBackBtn"
    />

<TextSwitcher
    android:id="@+id/infomsg"
    android:layout_width="550dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" />

<ImageButton
    android:id="@+id/exitbtn"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Exit"
    android:scaleType="fitCenter"
    android:onClick="onExitBtn"
    android:background="@drawable/exitbutton"
    />
</LinearLayout>

Upvotes: 1

Hardik Joshi
Hardik Joshi

Reputation: 9507

Use

android:background="@drawable/backbutton"

instead of

android:src="@drawable/backbutton"

Upvotes: 5

Related Questions