0

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? enter image description here

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>

1
  • 1
    try using scaletype tag in imageview Commented May 7, 2015 at 18:12

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.