LayoutParams设置无效可能的原因

来源:互联网 发布:战国之怒进阶数据 编辑:程序博客网 时间:2024/05/16 10:04

控件是不是还设置了权重比例android:layout_weight属性。

weight属性的优先级要高于LayoutParams设定的值。简单来说就是你不能“又要让马儿跑,又不让马儿吃草”,既然定死了所占比例,当然就无法同时设置其它的尺寸了。

解决办法也简单:

①(去TM的权重(╯‵□′)╯︵┻━┻):将weight属性删去,自己在java代码中重新设计尺寸

②(不不不,还是权重要紧_(:з」∠)_):在控件外层套一层Layout,在该Layout上设置权重。同时JAVA代码对控件尺寸再调整。


二是不是控件带入了过大/小尺寸的图片。

这种情况下控件受制于图片的尺寸使得整体过大,无法做到所要求的尺寸。需要对图片ImageView额外设置imageView.setScaleXY(适配方案);

setScaleXY方法有多种尺寸方案可选(属性位于ImageView.ScaleType类中),摘选如下:

Enum values

ScaleTypeCENTER

Center the image in the view, but perform no scaling. 

中心的图像在视图中,但是没有执行缩放。

ScaleTypeCENTER_CROP

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). 

将图像均匀地缩放(保持图像的宽比),这样图像的大小(宽度和高度)将等于或大于视图的相应维度(减去填充)。

ScaleTypeCENTER_INSIDE

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). 

将图像均匀地缩放(保持图像的宽比),这样图像的大小(宽度和高度)就等于或小于视图的相应维度(减去填充)。

ScaleTypeFIT_CENTER

Scale the image using CENTER.

使用中心缩放图像。常用属性值,即是说在保持原有图像比例的前提下充满父容器。

ScaleTypeFIT_END

Scale the image using END.

使用末端缩放图像。

ScaleTypeFIT_START

Scale the image using START.

使用前端缩放图像。

ScaleTypeFIT_XY

Scale the image using FILL.

使用填充来缩放图像。常用属性,不管图片原比例,按父容器比例拉伸图片。

ScaleTypeMATRIX

Scale using the image matrix when drawing. 

绘图时使用图像矩阵的尺度。



阅读全文
0 0