umar
umar

Reputation: 3133

setting up background image

i want to set the background like below

enter image description here

but i am getting like this

enter image description here

when i cropped the image to half i was getting like this (blur)

enter image description here

The original image is enter image description here

please guide how can i set like original one

xml files Grid xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/GridItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    >



    <ImageView
        android:id="@+id/grid_item_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>

    <TextView
        android:id="@+id/grid_item_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:gravity="center_horizontal"
        android:textColor="#ffffff">
    </TextView>

</LinearLayout>

main xml

<?xml version="1.0" encoding="utf-8"?>
<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MyGrid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:columnWidth="80dp"
    android:stretchMode="columnWidth"
    android:gravity="center_horizontal"

        android:scaleType="fitXY"   
     android:background="@drawable/backimage"
 >
</GridView>

I was thinking that it might be due to wrong xml placement so i also tried without gridlayout but no luck so far .

Now i have created multiple folder for images like this enter image description here and in the manifest file add these line

<supports-screens  
     android:smallScreens="false"       android:normalScreens="true"
      android:largeScreens="true"
      android:anyDensity="true" />

please guide what else need to be done

Thanks

Upvotes: 0

Views: 3075

Answers (4)

albnok
albnok

Reputation: 530

Have you tried forcing it to 32-bit?

Within your onCreate:

getWindow().setFormat(PixelFormat.RGBA_8888);

Upvotes: 0

SteveWeber
SteveWeber

Reputation: 71

The truth is the best way is to rescale the original picture to the dimensions of your screen. The picture you want is a cropped inset of the original. (The red on the right is almost gone). So one way is to change the margins. The numbers below will depend on your screen resolution.

enter image description here

And here is the Main.xml:

<?xml version="1.0" encoding="utf-8"?>

android:background="@drawable/love"
android:id="@+id/imageView1"



android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-190px"
android:layout_marginRight="-210px"
android:layout_marginTop="-20px"
android:layout_marginBottom="-200px"

android:layout_gravity="fill_horizontal"

Upvotes: 3

Pedro Loureiro
Pedro Loureiro

Reputation: 11514

You are facing several problems.

  1. change the scale type to CENTER_INSIDE. I think this might be the one you want. Check others here: ImageView.ScaleType

  2. the blur may be caused by several things. I would put different drawables for different screen densities. See Supporting multiple screens

Upvotes: 1

papachan
papachan

Reputation: 1909

Where you put :

 android:scaleType="fitXY" 

I think you should use something like to maintain the image aspect ratio

android:scaleType="centerInside"

Upvotes: 1

Related Questions