1

I want following type of background from my image:

enter image description here

This is NOT a duplicate question because I've tried following solutions:

1) First one 2) Second 3) third

What these answers suggest is use of following attributes of image view:

android:scaleType="..."

I've tried each available values for this. What I'm getting is:

enter image description here

Or a very small image in the center, if I use android:scaleType="center".

Following is my layout file for this activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.admin.georeminder.MainActivity">


<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/view"
    android:src="@mipmap/landscape"
    android:scaleType="centerCrop" />

</RelativeLayout>

So what am I missing here? Any help will be appreciated! Thanks

EDIT

I've also tried following combination:

android:scaleType="fitXY"
android:adjustViewBounds="true"
Kaushal28
  • 5,377
  • 5
  • 41
  • 72
  • Instead of `match_parent` for width and height, use `wrap_content` – Alexandre May 24 '17 at 18:05
  • then it displays very small image at top left corner. – Kaushal28 May 24 '17 at 18:07
  • This is because the picture dimensions (width and height) are smaller than the screen size. You need a picture image file with larger dimensions. – Alexandre May 24 '17 at 18:08
  • no! Image size is 4288*2848 pixels. with size of 1.45 MB – Kaushal28 May 24 '17 at 18:09
  • Are you seeing this on layout designer or in device? Also, you should place images inside Res/drawable instead of Res/mipmap, mipmap is only for app launcher icons. – Alexandre May 24 '17 at 18:13
  • yes it is same when I run the app. Should I change the location ? – Kaushal28 May 24 '17 at 18:15
  • @Kaushal28 When I keep the image in drawable folder it is working fine. Did you try that? – Krish May 31 '17 at 12:18
  • Your question says that you're asking how to do FILL but in the picture you provided you are showing a centered image, not fill. Since you marked Alexandre's response as the answer I am assuming you did not want fill but rather center. In Android "centerCrop" is the tag used for fill and "center" is used for center. For a better understanding of terms see the Android documentation https://developer.android.com/reference/android/widget/ImageView.ScaleType – SendETHToThisAddress Mar 26 '19 at 13:25
  • @technoman23 that's why you down voted my question? – Kaushal28 Mar 26 '19 at 16:38

4 Answers4

2

Place your image file in Res/drawable instead of Res/mipmap.

Res/mipmap is for app launcher icons only

Try this:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:id="@+id/view"
    android:src="@drawable/landscape"
    android:scaleType="center" />
Alexandre
  • 565
  • 3
  • 9
1

use fitxy and use adjustviewbond=true

Hadi Khezrpor
  • 401
  • 5
  • 21
1

Set scaleType with centerCrop and centerInParent in your imageview

    <ImageView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:scaleType="centerCrop"
    android:id="@+id/view"
    android:src="@mipmap/landscape"       
    />
sasikumar
  • 12,540
  • 3
  • 28
  • 48
1

You could use FrameLayout and ImageView as background

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageView
    android:id="@+id/imgPlaylistItemBg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:maxHeight="0dp"
    android:scaleType="fitXY"
    android:src="@drawable/img_dsh" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
Thien Huu
  • 36
  • 3