Android FrameLayout内的图像未收缩,尽管scaletype设置为fitcenter
我有一个Android FrameLayout内的图像未收缩,尽管scaletype设置为fitcenter,android,android-framelayout,scaletype,Android,Android Framelayout,Scaletype,我有一个ImageView,它必须包装在Framelayout中。但是当我使用FrameLayout时,图像被剪裁在ImageView的范围内,并且即使我使用setScaleType(ScaleType.FitCenter),也不会使其“适合”;但是当我使用其他ViewGroup时,比如RelativeLayout`,结果是可以的。为什么?我能做什么?这是我的密码: FrameLayout profileimage_fl = new FrameLayout( ge
ImageView
,它必须包装在Framelayout
中。但是当我使用FrameLayout
时,图像被剪裁在ImageView
的范围内,并且即使我使用setScaleType(ScaleType.FitCenter),也不会使其“适合”;但是当我使用其他
ViewGroup时,比如
RelativeLayout`,结果是可以的。为什么?我能做什么?这是我的密码:
FrameLayout profileimage_fl = new FrameLayout(
getSherlockActivity());
layoutWidth = WindowSize.convertedHeight(150);
layoutHeight = WindowSize.convertedHeight(150);
p_ll = new LinearLayout.LayoutParams(layoutWidth, layoutHeight);
leftMargin = WindowSize.convertedWidth(1);
topMargin = WindowSize.convertedHeight(1);
rightMargin = WindowSize.convertedWidth(1);
bottomMargin = WindowSize.convertedHeight(1);
p_ll.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
profileimage_fl.setLayoutParams(p_ll);
profileimage_fl.setBackgroundColor(Color.LTGRAY);
ImageView profileimage = new ImageView(getSherlockActivity());
layoutWidth = WindowSize.convertedHeight(150);
layoutHeight = WindowSize.convertedHeight(150);
p_fl = new FrameLayout.LayoutParams(layoutWidth, layoutHeight);
profileimage.setLayoutParams(p_fl);
profileimage.setScaleType(ScaleType.FIT_CENTER);
profileimage.setPadding(WindowSize.convertedWidth(0),
WindowSize.convertedHeight(0), WindowSize.convertedHeight(0),
WindowSize.convertedWidth(0));
profileimage_fl.addView(profileimage);
然后我将
profileimage\u fl
添加到我在布局中膨胀的视图组中。该布局xml仅包含该视图组。你看,我通常不使用xml。你的框架布局有多大?匹配父项、包装内容、固定大小?我忘了提到我的框架布局是固定大小的。对不起,您可以发布您的布局xml吗?请参阅我编辑的问题,谢谢。我建议您完全按照您希望的方式在xml中创建布局。创建后,您可以对其进行编码。它将为您提供速度和确定性,您的代码将要实现的目标看起来是正确的(图像、帧布局等)。