How to resize image appropriately and set its height and width in android

I know this may strike out as a dumb question but i bet some of you had this problem before.From the screenshot,i am attempting to set an image in an activity.However my image brings up these spaces i dont know how to get rid of them.I mean is there a way,either in xml or to programmatically resize image to fit the height and width?In short,is there a way i can get rid of these spaces above and below?

My xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.snappy.stevekamau.cosmeticsapp.Categories.Lips">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar"></include>

    <ImageView
        android:id="@+id/imageTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/white_rectangle"
        android:src="@drawable/img4" />

    <TextView

        android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>
</RelativeLayout>

Answers


to make the bitmap fill the width and height you can add android:scaleType="fitXY" to your ImageView. This way your bitmap will be scaled in x and y independently, making your bitmap fill entirely the ImageView


Yes, it can be done by a single line of code. Here's the trick :)

android:adjustViewBounds="true"

Add this in ImageView.

<ImageView
        android:id="@+id/imageTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:background="@drawable/white_rectangle"
        android:src="@drawable/img4" />

Need Your Help

pass a selected value in a spinner array to another class Android

java android arrays android-intent spinner

im building an app that has self destructing images and i am trying to pass the value selected from the spinner to another class

Android: drawableLeft setting alpha

android android-edittext

Is there anyway to set alpha on a drawable sitting within an editText as a drawableLeft?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.