0

我使用 rowlayout.xml 和自定义适配器创建了一个自定义列表视图。heach 行有一对 textveiws 和背景,问题是如果我为该行设置背景图像,我无法降低高度。如果退出它,高度是如此之小。

我需要创建一个带有背景的自定义行并降低我无法做到的高度,我尝试更改重新 row.xml 高度,但它不起作用。在 android 的 ui 遮阳板中,它似乎可以工作,但是当我运行它时,该行永远不会改变他的大小。

这是该行的代码

<?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>
4

1 回答 1

0

您必须将背景图像的大小调整为与列表视图行的大小相同。

`   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;
    }
`
于 2013-07-14T07:53:04.687 回答