2013-05-29 103 views
0

我有一個FrameLayout,並希望添加2個ImageViews在彼此之上。 這是我的代碼Android:似乎「scaletype」被忽略,當多添加一個ImageView到一個FrameLayout?

FrameLayout.LayoutParams ImageViewParams = new  
FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, param_height);                

      ImageView mImageView = new ImageView(getActivity()); 
       mImageView.setScaleType(ScaleType.FIT_CENTER); 
       mImageView.setImageResource(mImageArray[counter]); 
       mImageView.setLayoutParams(ImageViewParams); 
      ImageView mImageView2 = new ImageView(getActivity()); 
       mImageView2.setBackgroundResource(mImageArray[counter]); 
       mImageView2.setScaleType(ScaleType.FIT_CENTER); 
       mImageView2.setLayoutParams(ImageViewParams); 

      FrameLayout mFrameLayout = new FrameLayout(getActivity()); 
      mFrameLayout.addView(mImageView); 

      if(counter != 0) 
      mFrameLayout.addView(mImageView2);  

mImageView2被拉伸。似乎「scaleType」被忽略? FrameLayout在TableLayout中。 TableLayout被填充到for循環中...

回答

2

我的錯誤! 我對mImageView2使用了「setBackgroundResource」而不是「setImageResource」。也許這有助於某人...