AndreiBogdan
AndreiBogdan

Reputation: 11164

Android. ImageView won't position itself correctly

I'm trying to place an image that fills the width of the screen, has the height of the actual image (wrap_content) and sits at the very bottom of the Layout.

I've wrote the below code, but between the second ImageView (the one with drawable/user_board) and the very bottom of the screen, there is a small space. Why is this? I've tried setting padding and margins to 0dp, but it seems it doesn't do the trick. Any ideas?

Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:id="@+id/LayoutBoard"
                android:noHistory="true"
                android:padding="0dp" >
    <ImageView
        android:src="@drawable/game_interface_background"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="matrix" />
    <ImageView
        android:src="@drawable/user_board"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"        
        android:layout_alignParentBottom="true"
        android:layout_margin="0dp"
        android:padding="0dp" />
</RelativeLayout>

Upvotes: 0

Views: 177

Answers (2)

Dmytro Titov
Dmytro Titov

Reputation: 3201

Doesn't your user_board image have some transparent space at the bottom? Or maybe you can try setting negative value in the padding field of the second ImageView.

Upvotes: 2

AggelosK
AggelosK

Reputation: 4341

Use android:scaleType="fitXY" and the bitmap contained in your ImageView will be resized to fit the whole ImageView. So using this attribute in both your imageViews will probably hide that empty space. However keep in mind that this does not keep the aspect ratio of the image. See here for more information about the android:scaleType attribute tag and the possible values it can take.

Upvotes: 1

Related Questions