user1256477
user1256477

Reputation: 11191

imagebutton height and width

I have a clasical android problem, butI can't solve it.

I have a imageButton, but it is deformed, the height is bigger than it should be, this is the code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="vertical" >

      <!-- other content -->
    
     </LinearLayout>
     
     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
     
        <ImageButton
            android:id="@+id/sabadell_but"
            android:background="@drawable/banner_sabadell"
            android:contentDescription="@string/infoDesc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom" />
       </LinearLayout>

    </LinearLayout>

this is what I should see:

enter image description here

And this is what i see:

enter image description here

How can I solve this?

Upvotes: 0

Views: 884

Answers (2)

Fahad Ishaque
Fahad Ishaque

Reputation: 1926

Try using scaleType = "fitCentre". Before that set height width wrap_content

This link would also help you to identify the scale type you want to use.

Upvotes: 1

Alex
Alex

Reputation: 1416

That is because you use your image as a background you should use it as a scource:

android:src="@drawable/banner_sabadell"

and if you'll got some problems with the size for different screens you'll got to play with an scale_type attribute

 android:scaleType="fitXY" /// or some others

and it will be better for you to make a 9patch image from your banner.. yeap, shure ... you got to make this:

android:background="#00000000"

or

android:background="@android:color/transparent"

Upvotes: 2

Related Questions