Question

I created a custom listview with rowlayout.xml and custom adapter. heach row has a pair of textveiws and background, the problem is i can't reduce the height if i set the background image for the row. if quit it the height is so small.

I need create a custom row with background and reduce the height how i cant, i tried change re row.xml height, but it doesn't work. in the android's ui visor it seems is going to work, but when I run it the row never changes his size.

this is the code for the row

<?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="80dp"
    android:orientation="horizontal"
    android:paddingLeft="@dimen/lateral_margin"
    android:paddingRight="@dimen/lateral_margin"
    android:background="@drawable/list_detail"
    >

    <TextView
        android:id="@+id/textItemOnList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"  />

    <TextView
        android:id="@+id/textMoneyOnList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true" />

</RelativeLayout>
Was it helpful?

Solution

You will have to resize your background image same the size of your listview row.

`   public static Bitmap resizeBitmap(Bitmap photo, float x, float y) {

        try {
            // get current bitmap width and height
            int width = photo.getWidth();
            int height = photo.getHeight();

            // determine how much to scale
            float scaleWidth = x / width;
            float scaleHeight = y / height;

            // create the matrix for the manipulation
            Matrix matrix = new Matrix();
            // resize the bitmap
            matrix.postScale(scaleWidth, scaleHeight);

            // recreate the new bitmap
            Bitmap resizebitmap = Bitmap.createBitmap(photo, 0, 0, width,
                    height, matrix, false);
            return resizebitmap;

        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
            System.gc();
        }
        return null;
    }
`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top