0

我想在我的应用程序的每一行的开头放置一个图像。问题是它缩小了图像太多 。我想让它占据整个空间

主.xml:

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:scrollbars="vertical"
        >
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:id="@+id/tableView"
        android:layout_height="fill_parent"
        android:layout_weight=".90"
        android:stretchColumns="1"
            ></TableLayout>
    </ScrollView>

这就是我添加图像的方式:

 TableLayout tableView = (TableLayout) findViewById(R.id.tableView);
        TableRow row = new TableRow(this);
        ImageView im;
        Bitmap bmp;
        im = new ImageView(this);
        bmp=getbmp(s);
    im.setImageBitmap(bmp);  
        row.addView(im, new TableRow.LayoutParams(70, 30)); 
        tableView.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT));

如果我从TableRow.LayoutParams(70, 30));图像中更改参数保持不变,则只有行变大/变小。此外,如果我使这些参数足够小,图像可能会变小,但这不是我想要做的。我 不一定 需要 整个 图片 , 一个 裁剪 的 放大 的 填充 那个 空间 也 很好 . 是来自网站的示例图像。如果我这样放图像:row.addView(im);图像变得太大,文本没有更多空间。

4

1 回答 1

2

可能对你有帮助

TableLayout tableView = (TableLayout) findViewById(R.id.tableView);

TableRow row = (TableRow) inflater.inflate(R.layout.tablerow, tableView, false);

ImageView imgDis = (ImageView) row.findViewById(R.id.spinnerEntryContactPhoto);

imgDis.setPadding(5, 5, 5, 5);
imgDis.setAdjustViewBounds(true);


// set row height width
TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 50);
params.topMargin = 0;
params.bottomMargin = 0;
params.leftMargin = 0;
params.rightMargin = 0;

// If you want to set margin of row
tableView.addView(row, params); 
tablerow.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView android:id="@+id/spinnerEntryContactPhoto"
        android:layout_gravity="center_vertical" 
        android:layout_width="70dip" 
        android:layout_height="30dip"/>
</TableRow>
于 2011-09-30T10:23:22.297 回答