How do I remove extra space above and below imageView?

后端 未结 11 1509
别跟我提以往
别跟我提以往 2020-12-08 05:57

I have a really simple image within a RelativeLayout and for some reason I am getting extra spacing on the top and bottom which I can\'t remove. How can I clear

相关标签:
11条回答
  • 2020-12-08 06:27

    just add ScaleType="fitxy" inside the Image view

    0 讨论(0)
  • 2020-12-08 06:28

    Must be enough adding the property:

    android:adjustViewBounds="true"
    

    for example:

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/slice11pp"
            android:adjustViewBounds="true" />
    

    0 讨论(0)
  • 2020-12-08 06:30

    In your above imageView just add android:scaleType="fitXY"

    0 讨论(0)
  • 2020-12-08 06:32

    Your problem is probably that you have no scale type set... Add it to the XML for the ImageView, "fitCenter" should be correct, but there are others, check: ScaleType.

    <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:src="@drawable/slice11pp"
                android:scaleType="fitCenter" />
    
    0 讨论(0)
  • 2020-12-08 06:32

    Use drawable-nodpi folder if there is no specific requirement for images. Then android: adjustViewBounds = "true" acts as the default.

    If you use drawable-nodpi you don't need to set android:adjustViewBounds = "true".

    I think this is the most effortless method.

    0 讨论(0)
  • 2020-12-08 06:32

    this is the perfect solution

     <ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    />
    

    it will not leave any extra single dp in any side. however the image will be distorted if it is not portrait image.

    0 讨论(0)
提交回复
热议问题