【问题标题】:Table row Image size problems表格行图片大小问题
【发布时间】:2011-09-30 10:05:51
【问题描述】:

我想在我的应用程序的每一行的开头放置一个图像。问题是它缩小了图像 too much 。我想让它占据the whole space

main.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)); 更改参数,图像保持不变,只有行变大/变小。此外,如果我使这些参数足够小,图像可能会变小,但这不是我想要做的。我 不一定 需要 整个 图片 , 一个 裁剪 的 放大 的 填充 那个 空间 也 很好 . This 是来自网站的示例图片。如果我这样放图片:row.addView(im); 图片太大了,文字就没有空间了。

【问题讨论】:

标签: android image view scale image-size


【解决方案1】:

可能对你有帮助

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>

【讨论】:

  • LayoutInflater inflater = getLayoutInflater();写在tablerow的上面。
  • imgDis.setAdjustViewBounds(true);确实成功了,谢谢!
猜你喜欢
  • 2014-11-15
  • 2013-02-22
  • 1970-01-01
  • 2013-11-25
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多