1
我不知道爲什麼這不能正常工作。我在佈局容器中添加圖像。我希望圖像爲768x1024,容器爲500x500。我這樣做是爲了讓我可以在遊戲中滑動圖像,但是我無法讓圖像比容器更大。圖像大小調整爲容器的大小。Android調整ImageView內部佈局
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);
'ImageView.setScaleType()'http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType – Simon
這確實不改變ImageView的大小隻會改變ImageView內部的圖像。 – Bobby