Search code examples
androidxmlandroid-layoutnine-patch

9patch stretches vertically, but does not horizontally


I created a 9patch image and somehow it does only stretch vertically. I tried other 9-patch images, but they have the same effect, whyle they work in other situations. So the 9patch should be fine I think. This is my XML code:

..
     <ImageView
            android:id="@+id/bottombar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:contentDescription="@string/app_name"
            android:src="@drawable/bar" />

        </RelativeLayout>

Anybody had the same issue and know how to solve it?

Thanks


Solution

  • If you are sure that the height of your View is really taller than the current image (as the others have suggested) then you should change your ImageViews scaleType. The default is FIT_CENTER which does not stretch the image, you should set it to FIT_XY.

    Also you may try to set your 9-png file as the background of your ImageView not as the src and I think this will also stretch the file.