Amol
Amol

Reputation: 285

How to resize Image to specific size in android layout?

I am trying to create a image button and I want to give the specific width and height to it, but my image size 512 x 512 and when activity starts layout is distorted because of the image.

Is there anyway I can resize it to some specific size?

                   <Button
        android:id="@+id/prev"
        android:text=""
        android:gravity="center"
        android:width="20dp"
        android:height="20dp"
        android:background="@drawable/go_prev"
            />  

Upvotes: 1

Views: 2743

Answers (2)

iTech
iTech

Reputation: 18440

You can specify the size in px which will be physical pixels instead of dp (Density-independent pixel); However, you should not do this if your app should support multiple screens.

Also, consider using android:layout_height and android:layout_width instead of height and width

Upvotes: 0

Gabe Sechan
Gabe Sechan

Reputation: 93561

Yes. Set your layout_width and layout_height to numeric values and it will fix the image to that exact size. You can then control how its scaled or cropped vi the scaleType parameter. Be careful specifying dp or px- dp will let you specify it in 160ths of an inch, px will be phyiscal pixels (but may be any real world size).

Upvotes: 2

Related Questions