Search code examples
androidandroid-layoutandroid-studioandroid-imageviewandroid-relativelayout

Removing space above and below ImageView in Android


Hello I need help as i Am adding an ImageView in my android xml file and i get an extra space above and below it i have tried to see the options that i can use to remove it one of them was adding android:adjustViewBounds="true" but when i do that that it removes my action Bar completely below is my code

<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.example.fred.yebo.MainFragment">

  <ImageView
      android:id="@+id/yeboAdd"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:src="@drawable/dice"

      />

</RelativeLayout>

Solution

  • Try this attribute :

    android:adjustViewBounds="true"
    

    automatically scales the height of the View.

    <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.example.fred.yebo.MainFragment">
    
        <ImageView
            android:id="@+id/yeboAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/cal" />
    
    </RelativeLayout>
    

    Please check this answer.