1

我不知道为什么这不能正常工作。我正在布局容器内添加图像。我希望图像为 768x1024,容器为 500x500。我这样做是为了可以在图像周围滑动以进行游戏,但我无法使图像大于容器。图像调整为容器的大小。

          containerView = new RelativeLayout(this);
     RelativeLayout.LayoutParams layoutForContainer = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
     layoutForContainer.height = 500;
     layoutForContainer.width = 500;
     layoutForContainer.addRule(RelativeLayout.CENTER_IN_PARENT);
     containerView.setLayoutParams(layoutForContainer);  
     layout.addView(containerView); 

     myImageView = new ImageView(this);
     myImageView.setImageResource(R.drawable.myImage); 
     RelativeLayout.LayoutParams layoutForLargeImage = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
     layoutForLargeImage.height = 768;
     layoutForLargeImage.width = 1024;
     myImageView.setLayoutParams(layoutForLargeImage); 
     containerView.addView(myImageView);
4

1 回答 1

0

使用以下代码:

myImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
myImageView.setAdjustViewBounds(true);
于 2013-09-28T13:47:13.397 回答