Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何以编程方式在TableRow内设置ImageView的宽度_Android_Android Layout - Fatal编程技术网

Android:如何以编程方式在TableRow内设置ImageView的宽度

Android:如何以编程方式在TableRow内设置ImageView的宽度,android,android-layout,Android,Android Layout,如何以编程方式在TableRow内设置ImageView的宽度?我不想改变单元格宽度,只想改变单元格内图像的宽度 布局:(省略号用于减少代码) 编辑:我希望图像在我设置的边界内裁剪,并使表格单元格为原始宽度。下面是由于parag的建议而对我起作用的代码示例: Bitmap bmp = BitmapFactory.decodeResource(getResources() , R.drawable.apple); int width = 50; int height = 44; Bitmap

如何以编程方式在TableRow内设置ImageView的宽度?我不想改变单元格宽度,只想改变单元格内图像的宽度

布局:(省略号用于减少代码)


编辑:我希望图像在我设置的边界内裁剪,并使表格单元格为原始宽度。下面是由于parag的建议而对我起作用的代码示例:

Bitmap bmp = BitmapFactory.decodeResource(getResources() , R.drawable.apple); 
int width = 50;
int height = 44; 
Bitmap resizedbitmap = Bitmap.createBitmap(bmp, iv.getScrollX(), iv.getScrollY(), width, height);
iv.setImageBitmap(resizedbitmap);

是否要缩放图像?还是修剪它

要缩放,请尝试ImageView。和矩阵

如果不想计算矩阵,可以尝试使用矩形(边界框)。使用ImageView获取原始rect。然后定义你想要的矩形并使用矩阵。创建图像矩阵


否则,您是否尝试过ImageView.?

调整位图大小的另一种方法

    ImageView img=(ImageView)findViewById(R.id.ImageView01);
    Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
    int width=200;
    int height=200;
    Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
    img.setImageBitmap(resizedbitmap);

setMaxWidth不起作用。我尝试了你的建议,但是Matrix.setRectToRect需要一个Bitmap.Config来缩放图像。这正是我所需要的
Bitmap bmp = BitmapFactory.decodeResource(getResources() , R.drawable.apple); 
int width = 50;
int height = 44; 
Bitmap resizedbitmap = Bitmap.createBitmap(bmp, iv.getScrollX(), iv.getScrollY(), width, height);
iv.setImageBitmap(resizedbitmap);
    ImageView img=(ImageView)findViewById(R.id.ImageView01);
    Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
    int width=200;
    int height=200;
    Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
    img.setImageBitmap(resizedbitmap);