创建dyanamic规则 [英] create dyanamic rule

查看:74
本文介绍了创建dyanamic规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动态调整大小的图像是在相对布局使用code

I am trying to dynamically resize an image which is in the relative layout using the code

int height = v.getHeight();
   int width = v.getWidth();
height += 50;
width += 50; 
RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(height, width);
layout.setMargins(200, 200, 200, 200);
layout.addRule(RelativeLayout.CENTER_IN_PARENT);
    v.setLayoutParams(layout);

下面v是一个视图(在这种情况下的ImageView) 该规则完美的作品。图像被放置在中央,但我想要得到的是图像应该放置在哪里。 即如果该图像是在位置(100,100)它的尺寸应该增加和图像应该放置在相同的位置或其中i需要将其放置的位置。 任何人都可以给我建议吧。

Here v is a view (a imageView in this case) The rule works perfectly. The image gets placed in the center but what i want to get is the image should be placed where it is. That is if the image is at the location (100,100) it's size should be increased and the image should be placed at the same location or the location where i need to place it. Can anyone suggest me please.

推荐答案

你所要求的,不能简单地通过创建规则进行。 你需要做额外的工作对这种对齐。

What you are asking, can't be done simply by creating rules. You need to do the extra work for such alignment.

1)使用addRule对齐父左,放大器;调整父顶部,然后将左,上边距将图像调整到你想要100,100或200,50后等等,你可以调整图片的大小不改变立场的任何位置。

1) use addRule to align parent left & align parent top, then set the left and top margin to align the image to any position you want 100,100 or 200, 50 etc. after that you can resize the image without changing position.

2),如果你保持图像对准CENTER_IN_PARENT那么图像大小调整是有点典型。 需要根据增加的大小,以增加的左侧和顶部填充对齐图像在中心

2) if you keep the image aligned CENTER_IN_PARENT then the image resize is a bit typical. you need to increase the left and top padding according to the increased size to align the image in center.

假设图像大小为100×100,新的大小是150×150
现在你需要设置布局参数宽X高为200×200,并设置图像的左侧和顶部边距为50。

suppose image size is 100x100 and new size is 150x150
now you need to set layout parameters to width x height to 200x200 and set the left and top padding of image to 50.

我希望它清楚

这篇关于创建dyanamic规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆