Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with 9 patch image as background

I have a list view structure, with Relative layout that uses alternating background images for odd/even elements. I'm trying to set the background drawable dynamically by calculating the position. It worked fine with the normal bitmap. But when I tried to use the ninepatch image it breaks the UI, all the elements get distorted. What am I doing wrong? Could it be how the ninepatch image is created or is there a different way to use a ninepatch image compared to a normal bitmap.

My List View XML goes like this

<?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="wrap_content" android:id="@+id/id01"
       android:background="@drawable/my_9patch_bg_image">
       <ImageView  />
       <RelativeLayout>
         <ImageView  />
          <TextView  />
          <TextView  />
       </RelativeLayout>
</RelativeLayout>

May be the solution here might work for my problem. It's exact though I have to try it.

like image 253
Sharief Shaik Avatar asked Feb 18 '11 11:02

Sharief Shaik


People also ask

What is the difference between a regular .PNG and a nine patch image?

A NinePatch graphic is a standard PNG image that includes an extra 1-pixel border. It must be saved with the 9. png extension in the res/drawable/ directory of your project.

What is 9 patch PNG?

A 9 patch image is a regular png (. PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image.

How do I create a 9 patch image in Photoshop?

Creating 9 patch background image using Photoshop:Draw the images in a regular way as you use to do in Photoshop. Make the 1px spacing around the image from all sides. And also make sure that the image doesn't have anything in this 1px area & has 100% transparency. Otherwise 9patch image will not work.

What is the nine patch images tool in Android?

The Draw 9-patch tool is a WYSIWYG editor included in Android Studio that allows you to create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. Selected parts of the image are scaled horizontally or vertically based on indicators drawn within the image.


1 Answers

Since nobody answered you for a year now... I had the same issue you need to setpadding of zero (even if you don't need it).

Good luck.

like image 119
zwebie Avatar answered Oct 03 '22 19:10

zwebie