Reputation: 3133
i want to set the background like below
but i am getting like this
when i cropped the image to half i was getting like this (blur)
The original image is
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
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
Reputation: 530
Have you tried forcing it to 32-bit?
Within your onCreate:
getWindow().setFormat(PixelFormat.RGBA_8888);
Upvotes: 0
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.
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
Reputation: 11514
You are facing several problems.
change the scale type to CENTER_INSIDE
. I think this might be the one you want. Check others here: ImageView.ScaleType
the blur may be caused by several things. I would put different drawables for different screen densities. See Supporting multiple screens
Upvotes: 1
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