0

我有一个 FrameLayout 并想在彼此之上添加 2 个 ImageView。这是我的代码

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 循环中填充...

4

1 回答 1

2

我的错!我对 mImageView2 使用了“setBackgroundResource”而不是“setImageResource”。也许这可以帮助某人...

于 2013-05-30T08:46:14.690 回答